Skip to content

Commit

Permalink
using windowScriptObjectAvailable delegate so the app gets set every …
Browse files Browse the repository at this point in the history
…time a page loads in the WebView, this way it works after reloading
  • Loading branch information
ryanb committed Jan 19, 2010
1 parent 6cae579 commit 0cbb1bc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 82 deletions.
10 changes: 7 additions & 3 deletions AppDelegate.m
Expand Up @@ -3,9 +3,6 @@
@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Allow this class to be usable through the "window.app" object in JavaScript
// This could be any Objective-C class
[[webView windowScriptObject] setValue:self forKey:@"app"];
[webView setMainFrameURL:[self appURL]];
}

Expand Down Expand Up @@ -49,4 +46,11 @@ - (IBAction)changeGreeting:(id)sender {
[[webView windowScriptObject] evaluateWebScript:@"changeGreeting('Hello from Objective-C!')"];
}

// This delegate method gets triggered every time the page loads, but before the JavaScript runs
- (void)webView:(WebView *)webView windowScriptObjectAvailable:(WebScriptObject *)windowScriptObject {
// Allow this class to be usable through the "window.app" object in JavaScript
// This could be any Objective-C class
[windowScriptObject setValue:self forKey:@"app"];
}

@end
61 changes: 28 additions & 33 deletions Cocoa Web App.xcodeproj/rbates.mode1v3
Expand Up @@ -271,8 +271,8 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
<integer>3</integer>
<integer>1</integer>
<integer>12</integer>
<integer>5</integer>
<integer>0</integer>
</array>
</array>
Expand Down Expand Up @@ -326,18 +326,17 @@
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>DC924C021105233C00E5D32F</string>
<string>DC4C7364110635A900A0A6C1</string>
<key>history</key>
<array>
<string>DC924B6C1105129000E5D32F</string>
<string>DC924B6D1105129000E5D32F</string>
<string>DC924B951105133A00E5D32F</string>
<string>DC924BA6110517A300E5D32F</string>
<string>DC924BA7110517A300E5D32F</string>
<string>DC924BA8110517A300E5D32F</string>
<string>DC924BEF1105218900E5D32F</string>
<string>DC924BF51105223900E5D32F</string>
<string>DC924BF01105218900E5D32F</string>
<string>DC4C72F911062D4E00A0A6C1</string>
</array>
</dict>
<key>SplitCount</key>
Expand All @@ -349,14 +348,14 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 0}, {1032, 430}}</string>
<string>{{0, 0}, {1032, 417}}</string>
<key>RubberWindowFrame</key>
<string>407 363 1240 665 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
<key>Proportion</key>
<string>430pt</string>
<string>417pt</string>
</dict>
<dict>
<key>ContentConfiguration</key>
Expand All @@ -369,14 +368,14 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 435}, {1032, 189}}</string>
<string>{{0, 422}, {1032, 202}}</string>
<key>RubberWindowFrame</key>
<string>407 363 1240 665 0 0 1680 1028 </string>
</dict>
<key>Module</key>
<string>XCDetailModule</string>
<key>Proportion</key>
<string>189pt</string>
<string>202pt</string>
</dict>
</array>
<key>Proportion</key>
Expand All @@ -395,9 +394,9 @@
</array>
<key>TableOfContents</key>
<array>
<string>DC924B711105129000E5D32F</string>
<string>DC4C73511106356200A0A6C1</string>
<string>1CE0B1FE06471DED0097A5F4</string>
<string>DC924B721105129000E5D32F</string>
<string>DC4C73521106356200A0A6C1</string>
<string>1CE0B20306471E060097A5F4</string>
<string>1CE0B20506471E060097A5F4</string>
</array>
Expand Down Expand Up @@ -535,11 +534,11 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
<string>DC924B7C1105129000E5D32F</string>
<string>DC924B7D1105129000E5D32F</string>
<string>DC4C7366110635A900A0A6C1</string>
<string>DC4C7367110635A900A0A6C1</string>
<string>1C78EAAD065D492600B07095</string>
<string>1CD10A99069EF8BA00B06720</string>
<string>DC924A9B1104EEEE00E5D32F</string>
<string>1C78EAAD065D492600B07095</string>
<string>/Users/rbates/code/cocoa-web-app/Cocoa Web App.xcodeproj</string>
</array>
<key>WindowString</key>
Expand All @@ -564,7 +563,7 @@
<key>PBXProjectModuleGUID</key>
<string>1CD0528F0623707200166675</string>
<key>PBXProjectModuleLabel</key>
<string>AppDelegate.m</string>
<string></string>
<key>StatusBarVisibility</key>
<true/>
</dict>
Expand All @@ -581,8 +580,6 @@
<string>218pt</string>
</dict>
<dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
Expand Down Expand Up @@ -622,7 +619,7 @@
<key>TableOfContents</key>
<array>
<string>DC924A9B1104EEEE00E5D32F</string>
<string>DC924B731105129000E5D32F</string>
<string>DC4C73531106356200A0A6C1</string>
<string>1CD0528F0623707200166675</string>
<string>XCMainBuildResultsModuleGUID</string>
</array>
Expand Down Expand Up @@ -666,8 +663,8 @@
<string>yes</string>
<key>sizes</key>
<array>
<string>{{0, 0}, {316, 185}}</string>
<string>{{316, 0}, {378, 185}}</string>
<string>{{0, 0}, {316, 198}}</string>
<string>{{316, 0}, {378, 198}}</string>
</array>
</dict>
<key>VerticalSplitView</key>
Expand All @@ -682,8 +679,8 @@
<string>yes</string>
<key>sizes</key>
<array>
<string>{{0, 0}, {694, 185}}</string>
<string>{{0, 185}, {694, 196}}</string>
<string>{{0, 0}, {694, 198}}</string>
<string>{{0, 198}, {694, 183}}</string>
</array>
</dict>
</dict>
Expand Down Expand Up @@ -716,7 +713,7 @@
<real>148</real>
</array>
<key>Frame</key>
<string>{{316, 0}, {378, 185}}</string>
<string>{{316, 0}, {378, 198}}</string>
<key>RubberWindowFrame</key>
<string>541 583 694 422 0 0 1680 1028 </string>
</dict>
Expand Down Expand Up @@ -744,13 +741,13 @@
<key>TableOfContents</key>
<array>
<string>1CD10A99069EF8BA00B06720</string>
<string>DC924B741105129000E5D32F</string>
<string>DC4C73541106356200A0A6C1</string>
<string>1C162984064C10D400B95A72</string>
<string>DC924B751105129000E5D32F</string>
<string>DC924B761105129000E5D32F</string>
<string>DC924B771105129000E5D32F</string>
<string>DC924B781105129000E5D32F</string>
<string>DC924B791105129000E5D32F</string>
<string>DC4C73551106356200A0A6C1</string>
<string>DC4C73561106356200A0A6C1</string>
<string>DC4C73571106356200A0A6C1</string>
<string>DC4C73581106356200A0A6C1</string>
<string>DC4C73591106356200A0A6C1</string>
</array>
<key>ToolbarConfiguration</key>
<string>xcode.toolbar.config.debugV3</string>
Expand Down Expand Up @@ -877,8 +874,6 @@
<key>Dock</key>
<array>
<dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
Expand Down Expand Up @@ -914,7 +909,7 @@
<key>TableOfContents</key>
<array>
<string>1C78EAAD065D492600B07095</string>
<string>DC924B7A1105129000E5D32F</string>
<string>DC4C7365110635A900A0A6C1</string>
<string>1C78EAAC065D492600B07095</string>
</array>
<key>ToolbarConfiguration</key>
Expand All @@ -924,7 +919,7 @@
<key>WindowToolGUID</key>
<string>1C78EAAD065D492600B07095</string>
<key>WindowToolIsVisible</key>
<true/>
<false/>
</dict>
<dict>
<key>Identifier</key>
Expand Down
73 changes: 28 additions & 45 deletions Cocoa Web App.xcodeproj/rbates.pbxuser
Expand Up @@ -16,9 +16,9 @@
};
256AC3D90F4B6AC300CF3369 /* AppDelegate.m */ = {
uiCtxt = {
sepNavIntBoundsRect = "{{0, 0}, {712, 910}}";
sepNavSelRange = "{1177, 0}";
sepNavVisRange = "{453, 327}";
sepNavIntBoundsRect = "{{0, 0}, {971, 741}}";
sepNavSelRange = "{1198, 0}";
sepNavVisRange = "{599, 1327}";
};
};
29B97313FDCFA39411CA2CEA /* Project object */ = {
Expand Down Expand Up @@ -55,20 +55,19 @@
PBXFileDataSource_Target_ColumnID,
);
};
PBXPerProjectTemplateStateSaveDate = 285535993;
PBXWorkspaceStateSaveDate = 285535993;
PBXPerProjectTemplateStateSaveDate = 285619541;
PBXWorkspaceStateSaveDate = 285619541;
};
perUserProjectItems = {
DC4C72F911062D4E00A0A6C1 /* PBXTextBookmark */ = DC4C72F911062D4E00A0A6C1 /* PBXTextBookmark */;
DC4C7364110635A900A0A6C1 /* PBXTextBookmark */ = DC4C7364110635A900A0A6C1 /* PBXTextBookmark */;
DC924B6C1105129000E5D32F /* PlistBookmark */ = DC924B6C1105129000E5D32F /* PlistBookmark */;
DC924B6D1105129000E5D32F /* PBXTextBookmark */ = DC924B6D1105129000E5D32F /* PBXTextBookmark */;
DC924B951105133A00E5D32F /* PBXTextBookmark */ = DC924B951105133A00E5D32F /* PBXTextBookmark */;
DC924BA6110517A300E5D32F /* PBXBookmark */ = DC924BA6110517A300E5D32F /* PBXBookmark */;
DC924BA7110517A300E5D32F /* PBXBookmark */ = DC924BA7110517A300E5D32F /* PBXBookmark */;
DC924BA8110517A300E5D32F /* PBXBookmark */ = DC924BA8110517A300E5D32F /* PBXBookmark */;
DC924BEF1105218900E5D32F /* PBXTextBookmark */ = DC924BEF1105218900E5D32F /* PBXTextBookmark */;
DC924BF01105218900E5D32F /* PBXTextBookmark */ = DC924BF01105218900E5D32F /* PBXTextBookmark */;
DC924BF51105223900E5D32F /* PBXTextBookmark */ = DC924BF51105223900E5D32F /* PBXTextBookmark */;
DC924C021105233C00E5D32F /* PBXTextBookmark */ = DC924C021105233C00E5D32F /* PBXTextBookmark */;
};
sourceControlManager = DC924A9D1104EEEE00E5D32F /* Source Control */;
userBuildSettings = {
Expand All @@ -80,6 +79,26 @@
DC924A8C1104EEEB00E5D32F /* Cocoa Web App */,
);
};
DC4C72F911062D4E00A0A6C1 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 256AC3D90F4B6AC300CF3369 /* AppDelegate.m */;
name = "AppDelegate.m: 47";
rLen = 0;
rLoc = 1412;
rType = 0;
vrLen = 1051;
vrLoc = 687;
};
DC4C7364110635A900A0A6C1 /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 256AC3D90F4B6AC300CF3369 /* AppDelegate.m */;
name = "AppDelegate.m: 38";
rLen = 0;
rLoc = 1198;
rType = 0;
vrLen = 1327;
vrLoc = 599;
};
DC924A8C1104EEEB00E5D32F /* Cocoa Web App */ = {
isa = PBXExecutable;
activeArgIndices = (
Expand Down Expand Up @@ -140,7 +159,7 @@
);
name = "/Users/rbates/code/cocoa-web-app/Cocoa_Web_App-Info.plist";
rLen = 0;
rLoc = 9223372036854775807;
rLoc = 9223372036854775808;
};
DC924B6D1105129000E5D32F /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
Expand All @@ -152,22 +171,6 @@
vrLen = 45;
vrLoc = 0;
};
DC924B951105133A00E5D32F /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = DC924B961105133A00E5D32F /* AppDelegate.s */;
name = "AppDelegate.s: 1";
rLen = 0;
rLoc = 0;
rType = 0;
vrLen = 1262;
vrLoc = 0;
};
DC924B961105133A00E5D32F /* AppDelegate.s */ = {
isa = PBXFileReference;
name = AppDelegate.s;
path = "/Users/rbates/code/cocoa-web-app/build/Cocoa Web App.build/Debug/Cocoa Web App.build/Objects-normal/x86_64/AppDelegate.s";
sourceTree = "<absolute>";
};
DC924BA6110517A300E5D32F /* PBXBookmark */ = {
isa = PBXBookmark;
fRef = DC924BA0110515D700E5D32F /* dogcow.png */;
Expand All @@ -190,16 +193,6 @@
vrLen = 319;
vrLoc = 0;
};
DC924BF01105218900E5D32F /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 256AC3D90F4B6AC300CF3369 /* AppDelegate.m */;
name = "AppDelegate.m: 42";
rLen = 0;
rLoc = 1463;
rType = 0;
vrLen = 1051;
vrLoc = 647;
};
DC924BF51105223900E5D32F /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = DC924AB41105110500E5D32F /* index.html */;
Expand All @@ -210,14 +203,4 @@
vrLen = 985;
vrLoc = 521;
};
DC924C021105233C00E5D32F /* PBXTextBookmark */ = {
isa = PBXTextBookmark;
fRef = 256AC3D90F4B6AC300CF3369 /* AppDelegate.m */;
name = "AppDelegate.m: 47";
rLen = 0;
rLoc = 1593;
rType = 0;
vrLen = 1051;
vrLoc = 687;
};
}
10 changes: 9 additions & 1 deletion English.lproj/MainMenu.xib
Expand Up @@ -1141,6 +1141,14 @@
</object>
<int key="connectionID">555</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">frameLoadDelegate</string>
<reference key="source" ref="637869069"/>
<reference key="destination" ref="976324537"/>
</object>
<int key="connectionID">556</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
Expand Down Expand Up @@ -2059,7 +2067,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">555</int>
<int key="maxID">556</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand Down

0 comments on commit 0cbb1bc

Please sign in to comment.