To develop and build extensions you need a source tree, typically it is a good idea to use the latest trunk to benefit from the latest and greatest features or bug fixes. So if your extension uncovers a bug you can easily report it and get it fixed.

To develop and build extensions you need a source tree, typically it is a good idea to use the latest trunk to benefit from the latest and greatest features or bug fixes. So if your extension uncovers a bug you can easily report it and get it fixed.

For more details see [[contribute]] which also covers how to make a branch and codying style in detail.

For more details see [[contribute]] which also covers how to make a branch and codying style in detail.

Inside Midori, open the Preferences,​ go to Extensions, and look for your new extension in the list. Activate and be proud of completing the first part of the tutorial!

Inside Midori, open the Preferences,​ go to Extensions, and look for your new extension in the list. Activate and be proud of completing the first part of the tutorial!

Line 45:

Line 56:

<code vala>

<code vala>

-

void browser_added (Midori.Browser browser) {

+

namespace Sandcat {

-

​stdout.printf ​("a new browser was added, yay\n");

+

private class Manager : Midori.Extension {

-

}

+

+

internal Manager () {

+

GLib.Object (name: _("Furry example extension"​),

+

​description:​ _("Take care of petting cats"​),​

+

​version:​ "​0.1"​ + Midori.VERSION_SUFFIX,​

+

​authors:​ "Jane Doe <​email@domain.tld>"​);​

+

activate.connect (this.activated);​ //it will run the method activated

+

deactivate.connect (this.deactivated); //it will run the method deactivated

+

}

-

void activated (Midori.App app) {

+

void browser_added (Midori.Browser browser) {

-

foreach (var browser in app.get_browsers ())

+

stdout.printf ("a new browser was added, yay\n"​);​

-

browser_added (browser);​

+

}

-

app.add_browser.connect (browser_added);​

+

+

​void activated (Midori.App app) {

+

foreach (var browser in app.get_browsers ())

+

browser_added (browser);​

+

app.add_browser.connect (browser_added);​

+

}

+

+

void deactivated () {

+

var app = get_app ();

+

app.add_browser.disconnect (browser_added);​

+

}

+

}

}

}

-

void deactivated ​() {

+

public Midori.Extension extension_init ​() {

-

​var app = get_app ();

+

​return new Sandcat.Manager ​();

-

app.add_browser.disconnect ​(browser_added);

+

}

}

</​code>​

</​code>​

+

You'll see how when activated the extension gets an "​app"​ which is a running Midori instance. It has among other things knowledge of browser windows. It's good practise to not make any assumptions on how many windows are open.

-

In your Manager you connect these new callbacks:

+

====== Working with (web) views =====

<code vala>

<code vala>

-

this.activate.connect (activated);​

+

namespace Sandcat {

-

this.deactivate.connect (deactivated);​

+

private class Manager : Midori.Extension {

-

</​code>​

+

+

internal Manager () {

+

GLib.Object (name: _("​Furry example extension"​),​

+

​description:​ _("​Take care of petting cats"​),​

+

​version:​ "​0.1"​ + Midori.VERSION_SUFFIX,​

+

​authors:​ "Jane Doe <​email@domain.tld>"​);​

+

​activate.connect (this.activated);​

+

deactivate.connect (this.deactivated);​

+

}

-

You'll see how when activated the extension gets an "​app"​ which is a running ​Midori ​instance. It has among other things knowledge of browser ​windows. It's good practise to not make any assumptions on how many windows are open.

+

void tab_added (Midori.Browser ​browser, Midori.Tab tab) {

+

stdout.printf ("New tab added\n"​);​

+

}

-

====== Working with (web) views =====

+

void tab_switched (Midori.View?​ old_view, Midori.View?​ new_view) {

+

var title = new_view.get_display_title();​

+

var uri = new_view.get_display_uri();

+

stdout.printf ("​title:​ %s and url: %s\n", title, uri);

+

}

-

<code vala>

+

​void tab_removed ​() {

-

​void tab_added ​(Midori.Browser browser, Midori.Tab tab) {

+

​stdout.printf ("tab removed\n"​);

-

var view = tab as Midori.View;

+

}

-

string uri = tab.uri;

+

-

​string title = tab.title;​

+

-

​}

+

-

// in browser_added

+

void browser_added ​(Midori.Browser browser) {

-

foreach (var tab in browser.get_tabs ())

+

​foreach (var tab in browser.get_tabs ())

tab_added (browser, tab);

tab_added (browser, tab);

-

​browser.add_tab.connect (tab_added);​

+

browser.add_tab.connect (tab_added);​

+

​browser.switch_tab.connect (tab_switched);​

+

​browser.remove_tab.connect (tab_removed);​

+

}

-

// in destroyed

+

void activated (Midori.App app) {

-

foreach (var tab in browser.get_tabs ​())

+

foreach (var browser ​in app.get_browsers ​())

-

browser.add_tab_disconnect ​(tab_added);

+

​browser_added (browser);

-

</​code>​

+

app.add_browser.connect ​(browser_added);

+

}

+

void browser_removed (Midori.Browser browser) {

+

foreach (var tab in browser.get_tabs ()) {

+

browser.add_tab.disconnect (tab_added);​

+

browser.switch_tab.disconnect (tab_switched);​

+

browser.remove_tab.disconnect (tab_removed);​

+

}

+

}

+

+

void deactivated () {

+

var app = get_app ();

+

app.add_browser.disconnect (browser_added);​

+

foreach (var browser in app.get_browsers ())

+

browser_removed (browser);

+

}

+

}

+

}

+

+

public Midori.Extension extension_init () {

+

return new Sandcat.Manager ();

+

}

+

</​code>​

+

When you open a new tab you will see in a message "New tab added",​ if you switch between tabs you will get their title and url, and the last one is, close a tab, you will see a message "tab removed"​