What's new? | Help | Directory | Sign in
Google
             
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2008, Google Inc.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. Neither the name of Google Inc. nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#import "gears/base/common/common.h"
#import "gears/base/common/detect_version_collision.h"
#import "gears/base/common/exception_handler.h"
#import "gears/base/common/message_queue.h"
#import "gears/base/safari/browser_load_hook.h"
#import "gears/base/safari/safari_workarounds.h"
#import "gears/localserver/safari/http_handler.h"
#import "gears/localserver/safari/ui_thread.h"
#import "gears/ui/safari/settings_menu.h"
#import "gears/ui/safari/native_dialogs_osx.h"

static ExceptionManager exception_manager(true);

@implementation GearsBrowserLoadHook
+ (BOOL)installHook {
#ifdef OFFICIAL_BUILD
// Init Breakpad.
LOG(("Gears: Before BreakPad.StartMonitoring()"));
exception_manager.StartMonitoring();
LOG(("Gears: After BreakPad.StartMonitoring()"));
#endif
SetUiThread();
if (!ThreadMessageQueue::GetInstance()->InitThreadMessageQueue()) {
LOG(("Gears: MessageQueue Init failed"));
}

// If there is a version collision, don't register HTTP interception hoooks.
if (DetectedVersionCollision()) {
LOG(("Gears: Version collision detected"));
} else {
// Register HTTP intercept hook.
if (![GearsHTTPHandler registerHandler]) {
LOG(("GearsHTTPHandler registerHandler failed"));
return NO;
}

// Install workarounds.
LOG(("Gears: Installing protocol workaround"));
ApplyProtocolWorkaround();
LOG(("Gears: protocol workaround installed"));
}

// Register an applicationDidFinishLaunching delegeate
GearsBrowserLoadHook *inst = [[GearsBrowserLoadHook alloc] init];
if (!inst) {
LOG(("GearsBrowserLoadHook init failed"));
return NO;
}
LOG(("GearsBrowserLoadHook object created"));

NSApplication *app = [NSApplication sharedApplication];
if (!app) {
LOG(("NSApplication sharedApplication returned NULL"));
return NO;
}

// Make sure we don't try to add our Notification listener more than once.
static bool notification_hook_installed = false;
assert(!notification_hook_installed);
if (!notification_hook_installed) {
LOG(("Gears: adding finishlaunching notification hook"));
[[NSNotificationCenter defaultCenter]
addObserver:inst
selector:@selector(applicationDidFinishLaunching:)
name:NSApplicationDidFinishLaunchingNotification
object:app];
LOG(("Gears: added finishlaunching notification hook"));

LOG(("Gears: adding willterminate notification hook"));
[[NSNotificationCenter defaultCenter]
addObserver:inst
selector:@selector(applicationWillTerminate:)
name:NSApplicationWillTerminateNotification
object:app];
LOG(("Gears: added willterminate notification hook"));

LOG(("Gears: Loading Nibs"));
PreloadNibFiles();
LOG(("Gears: Nibs Loaded"));

notification_hook_installed = true;
} else {
LOG(("Gears: notification hook already installed"));
}

// If we got here then we loaded OK
LOG(("Loaded Gears version: " PRODUCT_VERSION_STRING_ASCII "\n" ));
return YES;
}

// Called at the end of the application's launch, when NIBs are loaded and
// the menu bar is ready.
// IMPORTANT: Note that if a 3rd party application manually loads Gears, they
// may do so after this notification has fired. Therefore this handler should
// NOT run any code that will cripple Gears' normal operation.
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
LOG(("Gears: finishlaunching hook called"));
// Install Settings Menu.
[GearsSettingsMenuEnabler installSettingsMenu];
LOG(("Gears: finishlaunching hook exited"));
}

// Called just before the application quits.
- (void)applicationWillTerminate:(NSNotification*)aNotification {
LOG(("Gears: applicationWillTerminate hook called"));
UnloadNibFiles();
LOG(("Gears: applicationWillTerminate hook exited"));
}
@end
Show details Hide details

Change log

r2816 by gears.daemon on Sep 09, 2008   Diff
[Author: playmobil]

Add opt-in screen for sending in Usage
Statistics so we don't send
crash logs without the user's express
permission.

PRESUBMIT=passed
R=waylonis,aa
CC=gears-internal
DELTA=1117  (1107 added, 0 deleted, 10
changed)
...
Go to: 
Project members, sign in to write a code review

Older revisions

r2650 by gears.daemon on Aug 08, 2008   Diff
[Author: playmobil]

Move call to PreloadNibFiles() out of N
SApplicationDidFinishLaunchingNotifica
tion
...
r2612 by gears.daemon on Aug 06, 2008   Diff
[Author: playmobil]

 Fix bug 635.

Initialize the Thread Message Queue on
...
r2508 by gears.daemon on Jul 25, 2008   Diff
[Author: bgarcia]

Update Safari to use SafeHttpRequest.

PRESUBMIT=passed
...
All revisions of this file

File info

Size: 5358 bytes, 134 lines