Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

45
Chapter 2 The Mechanism behind Extensions

Transcript of Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Page 1: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Chapter 2The Mechanism

behind Extensions

Page 2: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

How “Extensions”are implemented

Page 3: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

How is itdifferent from

plugins

Page 4: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Pluginis a small application that

interacts with the main application to provide a certain

function.

Page 5: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Firefox Extension is likedynamically applied

software patch

Page 6: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Patch?

Page 7: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Index: layout/xul/base/src/nsNativeScrollbarFrame.cpp===================================================================RCS file: /cvsroot/mozilla/layout/xul/base/src/nsNativeScrollbarFrame.cpp,vretrieving revision 1.22diff -u -6 -p -r1.22 nsNativeScrollbarFrame.cpp--- layout/xul/base/src/nsNativeScrollbarFrame.cpp 31 Dec 2004 01:13:26 -0000 1.22+++ layout/xul/base/src/nsNativeScrollbarFrame.cpp 28 Jul 2005 22:06:05 -0000@@ -342,6 +342,68 @@ nsNativeScrollbarFrame::Hookup() if (!curpos || error) return; scrollbar->SetPosition(curpos); } +NS_IMETHODIMP+nsNativeScrollbarFrame::Paint(nsPresContext* aPresContext,+ nsIRenderingContext& aRenderingContext,+ const nsRect& aDirtyRect,+ nsFramePaintLayer aWhichLayer,+ PRUint32 aFlags)+{+ if (NS_FRAME_IS_UNFLOWABLE & mState) {+ return NS_OK;+ }++ if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {+ PaintSelf(aPresContext, aRenderingContext, aDirtyRect);+ }++ return nsBoxFrame::Paint(aPresContext, aRenderingContext, aDirtyRect,+ aWhichLayer);+}

Page 8: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Applieddynamically?

Page 9: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Actually,

Page 10: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Key technologiesused in Firefox

Page 11: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

XULCSS

JavaScriptXPCOM

Page 12: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Can all be overwritten and appended after they'rebuilt and installed

Page 13: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.
Page 14: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

CSS

Page 15: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.
Page 16: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

XUL

Page 17: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

ComparingOverlay and JavaScript+DOM

Flexibility Maintainability

Overlay Low High

JavaScript+DOM High Low

Page 18: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.
Page 19: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

JavaScript

Page 20: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Examplevar obj = new Object();obj.objectProperty = new Object();obj.objectProperty.newProperty = 'string'obj.objectProperty.parent = obj;obj.myself = obj;

Page 21: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Examplevar obj = new Object();obj.name = 'Firefox';

function sayName() { alert(this.name);}obj.sayMyName = sayName;obj.sayMyName(); // says "Firefox"

Page 22: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Sample

Page 23: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

window.__original__open = window.open;window.open = function(aURI, aName, aFlag) { if (aURI.indexOf('.google.') > -1) return null; return this.__original__open(aURI, aName, aFlag);};window.open('http://www.google.co.jp/'); // will be blocked

Page 24: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.
Page 25: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

XPCOM

Page 26: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Keywords forXPCOM

Page 27: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

・ Component・ Interface・ Contract ID

Page 28: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Component↓

Small parts of applications(Libraries)

Page 29: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Interface↓

Input/Output standard for components

Page 30: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Contract ID↓

Name to identify components

Page 31: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Create a component with Same Interface

Same Nameas an existing component

Page 32: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Then

Page 33: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

You canreplace

the existing XPCOMcomponent with the

user created one

Page 34: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.
Page 35: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Summary

XUL Overlay+DOM

CSS Cascading

JavaScript Method overload

XPCOM Replace component

Page 36: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Different concept from plugins

Page 37: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Effect Format

PluginPerforms tasks requested by

FirefoxExternal application

Extension Modifies Firefox source code Patch

Page 38: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

But it is no ordinary

software patch

Page 39: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Because the patch application is

dynamic

Page 40: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

XULCSS

JavaScript

Are all interpretive, so they don't require compilers

Page 41: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Firefox can be configured and

modified in every way after it is

built and installed

Page 42: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

↓Extension

traits

Page 43: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Add/Remove Possibilities

Plugin Easy Limited

Conventional patch Difficult Unlimited

Extension Easy Unlimited

Page 44: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Conclusion

Page 45: Chapter 2 The Mechanism behind Extensions. How “Extensions” are implemented.

Extensions are very powerful customization tools when compared to plugins and

conventional patches