[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | a07676b2 | 2011-06-17 16:36:53 | [diff] [blame] | 5 | #include "chrome/browser/background/background_contents_service.h" |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 6 | |
| 7 | #include "base/basictypes.h" |
[email protected] | 1c1977cc | 2011-10-27 21:44:54 | [diff] [blame] | 8 | #include "base/bind.h" |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 9 | #include "base/command_line.h" |
| 10 | #include "base/string_util.h" |
| 11 | #include "base/utf_string_conversions.h" |
| 12 | #include "base/values.h" |
[email protected] | a07676b2 | 2011-06-17 16:36:53 | [diff] [blame] | 13 | #include "chrome/browser/background/background_contents_service_factory.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 14 | #include "chrome/browser/browser_process.h" |
| 15 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 16 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 17 | #include "chrome/browser/notifications/desktop_notification_service.h" |
| 18 | #include "chrome/browser/notifications/notification.h" |
| 19 | #include "chrome/browser/notifications/notification_ui_manager.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 20 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | f33bee5 | 2011-03-31 09:18:43 | [diff] [blame] | 21 | #include "chrome/browser/prefs/scoped_user_pref_update.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 22 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 23 | #include "chrome/browser/ui/browser.h" |
| 24 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 25 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 26 | #include "chrome/common/chrome_switches.h" |
| 27 | #include "chrome/common/extensions/extension.h" |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 28 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 29 | #include "chrome/common/pref_names.h" |
[email protected] | 5de63471 | 2011-03-02 00:20:19 | [diff] [blame] | 30 | #include "content/browser/site_instance.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 31 | #include "content/public/browser/notification_service.h" |
[email protected] | ef9572e | 2012-01-04 22:14:12 | [diff] [blame] | 32 | #include "content/public/browser/web_contents.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 33 | #include "grit/generated_resources.h" |
| 34 | #include "ui/base/l10n/l10n_util.h" |
| 35 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 36 | using content::WebContents; |
| 37 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 38 | namespace { |
| 39 | |
[email protected] | 7ec9b3d8 | 2011-04-13 17:19:21 | [diff] [blame] | 40 | const char kNotificationPrefix[] = "app.background.crashed."; |
| 41 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 42 | void CloseBalloon(const std::string id) { |
| 43 | g_browser_process->notification_ui_manager()->CancelById(id); |
| 44 | } |
| 45 | |
[email protected] | 7ec9b3d8 | 2011-04-13 17:19:21 | [diff] [blame] | 46 | void ScheduleCloseBalloon(const std::string& extension_id) { |
[email protected] | aa4e5ad4 | 2011-05-18 04:56:35 | [diff] [blame] | 47 | if (!MessageLoop::current()) // For unit_tests |
| 48 | return; |
[email protected] | 1c1977cc | 2011-10-27 21:44:54 | [diff] [blame] | 49 | MessageLoop::current()->PostTask( |
| 50 | FROM_HERE, base::Bind(&CloseBalloon, kNotificationPrefix + extension_id)); |
[email protected] | 7ec9b3d8 | 2011-04-13 17:19:21 | [diff] [blame] | 51 | } |
| 52 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 53 | class CrashNotificationDelegate : public NotificationDelegate { |
| 54 | public: |
| 55 | CrashNotificationDelegate(Profile* profile, const Extension* extension) |
| 56 | : profile_(profile), |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 57 | is_hosted_app_(extension->is_hosted_app()), |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 58 | extension_id_(extension->id()) { |
| 59 | } |
| 60 | |
| 61 | ~CrashNotificationDelegate() { |
| 62 | } |
| 63 | |
| 64 | void Display() {} |
| 65 | |
| 66 | void Error() {} |
| 67 | |
| 68 | void Close(bool by_user) {} |
| 69 | |
| 70 | void Click() { |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 71 | if (is_hosted_app_) { |
[email protected] | aa4e5ad4 | 2011-05-18 04:56:35 | [diff] [blame] | 72 | // There can be a race here: user clicks the balloon, and simultaneously |
| 73 | // reloads the sad tab for the app. So we check here to be safe before |
| 74 | // loading the background page. |
| 75 | BackgroundContentsService* service = |
| 76 | BackgroundContentsServiceFactory::GetForProfile(profile_); |
| 77 | if (!service->GetAppBackgroundContents(ASCIIToUTF16(extension_id_))) |
| 78 | service->LoadBackgroundContentsForExtension(profile_, extension_id_); |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 79 | } else { |
| 80 | profile_->GetExtensionService()->ReloadExtension(extension_id_); |
| 81 | } |
| 82 | |
[email protected] | 7ec9b3d8 | 2011-04-13 17:19:21 | [diff] [blame] | 83 | // Closing the balloon here should be OK, but it causes a crash on Mac |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 84 | // http://crbug.com/78167 |
[email protected] | 7ec9b3d8 | 2011-04-13 17:19:21 | [diff] [blame] | 85 | ScheduleCloseBalloon(extension_id_); |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | std::string id() const { |
[email protected] | 7ec9b3d8 | 2011-04-13 17:19:21 | [diff] [blame] | 89 | return kNotificationPrefix + extension_id_; |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | private: |
| 93 | Profile* profile_; |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 94 | bool is_hosted_app_; |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 95 | std::string extension_id_; |
| 96 | |
| 97 | DISALLOW_COPY_AND_ASSIGN(CrashNotificationDelegate); |
| 98 | }; |
| 99 | |
| 100 | void ShowBalloon(const Extension* extension, Profile* profile) { |
| 101 | string16 message = l10n_util::GetStringFUTF16( |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 102 | extension->is_app() ? IDS_BACKGROUND_CRASHED_APP_BALLOON_MESSAGE : |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 103 | IDS_BACKGROUND_CRASHED_EXTENSION_BALLOON_MESSAGE, |
| 104 | UTF8ToUTF16(extension->name())); |
| 105 | string16 content_url = DesktopNotificationService::CreateDataUrl( |
| 106 | extension->GetIconURL(Extension::EXTENSION_ICON_SMALLISH, |
| 107 | ExtensionIconSet::MATCH_BIGGER), |
| 108 | string16(), message, WebKit::WebTextDirectionDefault); |
| 109 | Notification notification( |
| 110 | extension->url(), GURL(content_url), string16(), string16(), |
| 111 | new CrashNotificationDelegate(profile, extension)); |
| 112 | g_browser_process->notification_ui_manager()->Add(notification, profile); |
| 113 | } |
| 114 | |
| 115 | } |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 116 | |
| 117 | // Keys for the information we store about individual BackgroundContents in |
| 118 | // prefs. There is one top-level DictionaryValue (stored at |
| 119 | // prefs::kRegisteredBackgroundContents). Information about each |
| 120 | // BackgroundContents is stored under that top-level DictionaryValue, keyed |
| 121 | // by the parent application ID for easy lookup. |
| 122 | // |
| 123 | // kRegisteredBackgroundContents: |
| 124 | // DictionaryValue { |
| 125 | // <appid_1>: { "url": <url1>, "name": <frame_name> }, |
| 126 | // <appid_2>: { "url": <url2>, "name": <frame_name> }, |
| 127 | // ... etc ... |
| 128 | // } |
[email protected] | ff4c1d8 | 2010-08-04 16:58:12 | [diff] [blame] | 129 | const char kUrlKey[] = "url"; |
| 130 | const char kFrameNameKey[] = "name"; |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 131 | |
| 132 | BackgroundContentsService::BackgroundContentsService( |
| 133 | Profile* profile, const CommandLine* command_line) |
[email protected] | 4c793f0 | 2010-08-18 20:55:45 | [diff] [blame] | 134 | : prefs_(NULL) { |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 135 | // Don't load/store preferences if the proper switch is not enabled, or if |
[email protected] | 2c910b7 | 2011-03-08 21:16:32 | [diff] [blame] | 136 | // the parent profile is incognito. |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 137 | if (!profile->IsOffTheRecord() && |
[email protected] | f9a0684 | 2010-08-21 00:32:40 | [diff] [blame] | 138 | !command_line->HasSwitch(switches::kDisableRestoreBackgroundContents)) |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 139 | prefs_ = profile->GetPrefs(); |
| 140 | |
| 141 | // Listen for events to tell us when to load/unload persisted background |
| 142 | // contents. |
| 143 | StartObserving(profile); |
| 144 | } |
| 145 | |
| 146 | BackgroundContentsService::~BackgroundContentsService() { |
| 147 | // BackgroundContents should be shutdown before we go away, as otherwise |
| 148 | // our browser process refcount will be off. |
| 149 | DCHECK(contents_map_.empty()); |
| 150 | } |
| 151 | |
[email protected] | da58f5b1 | 2010-11-10 19:31:12 | [diff] [blame] | 152 | std::vector<BackgroundContents*> |
| 153 | BackgroundContentsService::GetBackgroundContents() const |
| 154 | { |
| 155 | std::vector<BackgroundContents*> contents; |
| 156 | for (BackgroundContentsMap::const_iterator it = contents_map_.begin(); |
| 157 | it != contents_map_.end(); ++it) |
| 158 | contents.push_back(it->second.contents); |
| 159 | return contents; |
| 160 | } |
| 161 | |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 162 | void BackgroundContentsService::StartObserving(Profile* profile) { |
| 163 | // On startup, load our background pages after extension-apps have loaded. |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 164 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 165 | content::Source<Profile>(profile)); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 166 | |
| 167 | // Track the lifecycle of all BackgroundContents in the system to allow us |
| 168 | // to store an up-to-date list of the urls. Start tracking contents when they |
[email protected] | da58f5b1 | 2010-11-10 19:31:12 | [diff] [blame] | 169 | // have been opened via CreateBackgroundContents(), and stop tracking them |
| 170 | // when they are closed by script. |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 171 | registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 172 | content::Source<Profile>(profile)); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 173 | |
| 174 | // Stop tracking BackgroundContents when they have been deleted (happens |
| 175 | // during shutdown or if the render process dies). |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 176 | registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 177 | content::Source<Profile>(profile)); |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 178 | |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 179 | // Track when the BackgroundContents navigates to a new URL so we can update |
| 180 | // our persisted information as appropriate. |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 181 | registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 182 | content::Source<Profile>(profile)); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 183 | |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 184 | // Listen for new extension installs so that we can load any associated |
| 185 | // background page. |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 186 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 187 | content::Source<Profile>(profile)); |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 188 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 189 | // Track when the extensions crash so that the user can be notified |
| 190 | // about it, and the crashed contents can be restarted. |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 191 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 192 | content::Source<Profile>(profile)); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 193 | registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 194 | content::Source<Profile>(profile)); |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 195 | |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 196 | // Listen for extensions to be unloaded so we can shutdown associated |
| 197 | // BackgroundContents. |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 198 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 199 | content::Source<Profile>(profile)); |
[email protected] | 7ec9b3d8 | 2011-04-13 17:19:21 | [diff] [blame] | 200 | |
| 201 | // Make sure the extension-crash balloons are removed when the extension is |
| 202 | // uninstalled/reloaded. We cannot do this from UNLOADED since a crashed |
| 203 | // extension is unloaded immediately after the crash, not when user reloads or |
| 204 | // uninstalls the extension. |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 205 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 206 | content::Source<Profile>(profile)); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 207 | } |
| 208 | |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 209 | void BackgroundContentsService::Observe( |
| 210 | int type, |
| 211 | const content::NotificationSource& source, |
| 212 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 213 | switch (type) { |
| 214 | case chrome::NOTIFICATION_EXTENSIONS_READY: |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 215 | LoadBackgroundContentsFromManifests( |
| 216 | content::Source<Profile>(source).ptr()); |
| 217 | LoadBackgroundContentsFromPrefs(content::Source<Profile>(source).ptr()); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 218 | break; |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 219 | case chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED: |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 220 | BackgroundContentsShutdown( |
| 221 | content::Details<BackgroundContents>(details).ptr()); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 222 | break; |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 223 | case chrome::NOTIFICATION_BACKGROUND_CONTENTS_CLOSED: |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 224 | DCHECK(IsTracked(content::Details<BackgroundContents>(details).ptr())); |
| 225 | UnregisterBackgroundContents( |
| 226 | content::Details<BackgroundContents>(details).ptr()); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 227 | break; |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 228 | case chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 229 | DCHECK(IsTracked(content::Details<BackgroundContents>(details).ptr())); |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 230 | |
| 231 | // Do not register in the pref if the extension has a manifest-specified |
| 232 | // background page. |
| 233 | BackgroundContents* bgcontents = |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 234 | content::Details<BackgroundContents>(details).ptr(); |
| 235 | Profile* profile = content::Source<Profile>(source).ptr(); |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 236 | const string16& appid = GetParentApplicationId(bgcontents); |
| 237 | ExtensionService* extension_service = profile->GetExtensionService(); |
| 238 | // extension_service can be NULL when running tests. |
| 239 | if (extension_service) { |
| 240 | const Extension* extension = |
| 241 | extension_service->GetExtensionById(UTF16ToUTF8(appid), false); |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame^] | 242 | if (extension && extension->has_background_page()) |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 243 | break; |
| 244 | } |
[email protected] | aa4e5ad4 | 2011-05-18 04:56:35 | [diff] [blame] | 245 | RegisterBackgroundContents(bgcontents); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 246 | break; |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 247 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 248 | case chrome::NOTIFICATION_EXTENSION_LOADED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 249 | const Extension* extension = |
| 250 | content::Details<const Extension>(details).ptr(); |
| 251 | Profile* profile = content::Source<Profile>(source).ptr(); |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 252 | if (extension->is_hosted_app() && |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame^] | 253 | extension->has_background_page()) { |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 254 | // If there is a background page specified in the manifest for a hosted |
| 255 | // app, then blow away registered urls in the pref. |
| 256 | ShutdownAssociatedBackgroundContents(ASCIIToUTF16(extension->id())); |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 257 | |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 258 | ExtensionService* service = profile->GetExtensionService(); |
| 259 | if (service && service->is_ready()) { |
| 260 | // Now load the manifest-specified background page. If service isn't |
| 261 | // ready, then the background page will be loaded from the |
| 262 | // EXTENSIONS_READY callback. |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame^] | 263 | LoadBackgroundContents(profile, extension->GetBackgroundURL(), |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 264 | ASCIIToUTF16("background"), UTF8ToUTF16(extension->id())); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // Remove any "This extension has crashed" balloons. |
| 269 | ScheduleCloseBalloon(extension->id()); |
| 270 | break; |
| 271 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 272 | case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: |
| 273 | case chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 274 | Profile* profile = content::Source<Profile>(source).ptr(); |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 275 | const Extension* extension = NULL; |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 276 | if (type == chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED) { |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 277 | BackgroundContents* bg = |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 278 | content::Details<BackgroundContents>(details).ptr(); |
[email protected] | d2fad14 | 2011-04-15 10:18:44 | [diff] [blame] | 279 | std::string extension_id = UTF16ToASCII( |
| 280 | BackgroundContentsServiceFactory::GetForProfile(profile)-> |
| 281 | GetParentApplicationId(bg)); |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 282 | extension = |
| 283 | profile->GetExtensionService()->GetExtensionById(extension_id, false); |
| 284 | } else { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 285 | ExtensionHost* extension_host = |
| 286 | content::Details<ExtensionHost>(details).ptr(); |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 287 | extension = extension_host->extension(); |
| 288 | } |
| 289 | if (!extension) |
| 290 | break; |
| 291 | |
| 292 | // When an extension crashes, EXTENSION_PROCESS_TERMINATED is followed by |
| 293 | // an EXTENSION_UNLOADED notification. This UNLOADED signal causes all the |
| 294 | // notifications for this extension to be cancelled by |
| 295 | // DesktopNotificationService. For this reason, instead of showing the |
| 296 | // balloon right now, we schedule it to show a little later. |
[email protected] | 1c1977cc | 2011-10-27 21:44:54 | [diff] [blame] | 297 | MessageLoop::current()->PostTask( |
| 298 | FROM_HERE, base::Bind(&ShowBalloon, extension, profile)); |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 299 | break; |
| 300 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 301 | case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 302 | switch (content::Details<UnloadedExtensionInfo>(details)->reason) { |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 303 | case extension_misc::UNLOAD_REASON_DISABLE: // Fall through. |
| 304 | case extension_misc::UNLOAD_REASON_TERMINATE: // Fall through. |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 305 | case extension_misc::UNLOAD_REASON_UNINSTALL: |
[email protected] | 5e8bfe4 | 2011-01-18 20:31:13 | [diff] [blame] | 306 | ShutdownAssociatedBackgroundContents( |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 307 | ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> |
| 308 | extension->id())); |
[email protected] | 5e8bfe4 | 2011-01-18 20:31:13 | [diff] [blame] | 309 | break; |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 310 | case extension_misc::UNLOAD_REASON_UPDATE: { |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 311 | // If there is a manifest specified background page, then shut it down |
| 312 | // here, since if the updated extension still has the background page, |
| 313 | // then it will be loaded from LOADED callback. Otherwise, leave |
| 314 | // BackgroundContents in place. |
| 315 | const Extension* extension = |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 316 | content::Details<UnloadedExtensionInfo>(details)->extension; |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame^] | 317 | if (extension->has_background_page()) |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 318 | ShutdownAssociatedBackgroundContents(ASCIIToUTF16(extension->id())); |
[email protected] | 5e8bfe4 | 2011-01-18 20:31:13 | [diff] [blame] | 319 | break; |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 320 | } |
[email protected] | 5e8bfe4 | 2011-01-18 20:31:13 | [diff] [blame] | 321 | default: |
| 322 | NOTREACHED(); |
| 323 | ShutdownAssociatedBackgroundContents( |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 324 | ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> |
| 325 | extension->id())); |
[email protected] | 5e8bfe4 | 2011-01-18 20:31:13 | [diff] [blame] | 326 | break; |
| 327 | } |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 328 | break; |
[email protected] | 7ec9b3d8 | 2011-04-13 17:19:21 | [diff] [blame] | 329 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 330 | case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { |
[email protected] | 7ec9b3d8 | 2011-04-13 17:19:21 | [diff] [blame] | 331 | // Remove any "This extension has crashed" balloons. |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 332 | ScheduleCloseBalloon(*content::Details<const std::string>(details).ptr()); |
[email protected] | 7ec9b3d8 | 2011-04-13 17:19:21 | [diff] [blame] | 333 | break; |
| 334 | } |
| 335 | |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 336 | default: |
| 337 | NOTREACHED(); |
| 338 | break; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | // Loads all background contents whose urls have been stored in prefs. |
[email protected] | 1e0fe282 | 2010-06-24 21:04:19 | [diff] [blame] | 343 | void BackgroundContentsService::LoadBackgroundContentsFromPrefs( |
| 344 | Profile* profile) { |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 345 | if (!prefs_) |
| 346 | return; |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 347 | const DictionaryValue* contents = |
| 348 | prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); |
| 349 | if (!contents) |
| 350 | return; |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 351 | ExtensionService* extensions_service = profile->GetExtensionService(); |
[email protected] | da58f5b1 | 2010-11-10 19:31:12 | [diff] [blame] | 352 | DCHECK(extensions_service); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 353 | for (DictionaryValue::key_iterator it = contents->begin_keys(); |
| 354 | it != contents->end_keys(); ++it) { |
[email protected] | da58f5b1 | 2010-11-10 19:31:12 | [diff] [blame] | 355 | // Check to make sure that the parent extension is still enabled. |
| 356 | const Extension* extension = extensions_service->GetExtensionById( |
| 357 | *it, false); |
[email protected] | da58f5b1 | 2010-11-10 19:31:12 | [diff] [blame] | 358 | if (!extension) { |
| 359 | // We should never reach here - it should not be possible for an app |
| 360 | // to become uninstalled without the associated BackgroundContents being |
| 361 | // unregistered via the EXTENSIONS_UNLOADED notification, unless there's a |
[email protected] | 6aa25edc1 | 2011-10-06 02:16:11 | [diff] [blame] | 362 | // crash before we could save our prefs, or if the user deletes the |
| 363 | // extension files manually rather than uninstalling it. |
[email protected] | da58f5b1 | 2010-11-10 19:31:12 | [diff] [blame] | 364 | NOTREACHED() << "No extension found for BackgroundContents - id = " |
| 365 | << *it; |
[email protected] | 6aa25edc1 | 2011-10-06 02:16:11 | [diff] [blame] | 366 | // Don't cancel out of our loop, just ignore this BackgroundContents and |
| 367 | // load the next one. |
| 368 | continue; |
[email protected] | da58f5b1 | 2010-11-10 19:31:12 | [diff] [blame] | 369 | } |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 370 | LoadBackgroundContentsFromDictionary(profile, *it, contents); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 374 | void BackgroundContentsService::LoadBackgroundContentsForExtension( |
| 375 | Profile* profile, |
| 376 | const std::string& extension_id) { |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 377 | // First look if the manifest specifies a background page. |
| 378 | const Extension* extension = |
| 379 | profile->GetExtensionService()->GetExtensionById(extension_id, false); |
| 380 | DCHECK(!extension || extension->is_hosted_app()); |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame^] | 381 | if (extension && extension->has_background_page()) { |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 382 | LoadBackgroundContents(profile, |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame^] | 383 | extension->GetBackgroundURL(), |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 384 | ASCIIToUTF16("background"), |
| 385 | UTF8ToUTF16(extension->id())); |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | // Now look in the prefs. |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 390 | if (!prefs_) |
| 391 | return; |
| 392 | const DictionaryValue* contents = |
| 393 | prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); |
| 394 | if (!contents) |
| 395 | return; |
| 396 | LoadBackgroundContentsFromDictionary(profile, extension_id, contents); |
| 397 | } |
| 398 | |
| 399 | void BackgroundContentsService::LoadBackgroundContentsFromDictionary( |
| 400 | Profile* profile, |
| 401 | const std::string& extension_id, |
| 402 | const DictionaryValue* contents) { |
| 403 | ExtensionService* extensions_service = profile->GetExtensionService(); |
| 404 | DCHECK(extensions_service); |
| 405 | |
| 406 | DictionaryValue* dict; |
[email protected] | aa4e5ad4 | 2011-05-18 04:56:35 | [diff] [blame] | 407 | if (!contents->GetDictionaryWithoutPathExpansion(extension_id, &dict) || |
| 408 | dict == NULL) |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 409 | return; |
[email protected] | aa4e5ad4 | 2011-05-18 04:56:35 | [diff] [blame] | 410 | |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 411 | string16 frame_name; |
| 412 | std::string url; |
| 413 | dict->GetString(kUrlKey, &url); |
| 414 | dict->GetString(kFrameNameKey, &frame_name); |
| 415 | LoadBackgroundContents(profile, |
| 416 | GURL(url), |
| 417 | frame_name, |
| 418 | UTF8ToUTF16(extension_id)); |
| 419 | } |
| 420 | |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 421 | void BackgroundContentsService::LoadBackgroundContentsFromManifests( |
| 422 | Profile* profile) { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 423 | const ExtensionSet* extensions = |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 424 | profile->GetExtensionService()->extensions(); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 425 | ExtensionSet::const_iterator iter = extensions->begin(); |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 426 | for (; iter != extensions->end(); ++iter) { |
| 427 | const Extension* extension = *iter; |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame^] | 428 | if (extension->is_hosted_app() && extension->has_background_page()) { |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 429 | LoadBackgroundContents(profile, |
[email protected] | a03d4448f | 2012-01-10 23:25:28 | [diff] [blame^] | 430 | extension->GetBackgroundURL(), |
[email protected] | 41619a9a | 2011-04-13 20:07:32 | [diff] [blame] | 431 | ASCIIToUTF16("background"), |
| 432 | UTF8ToUTF16(extension->id())); |
| 433 | } |
| 434 | } |
| 435 | } |
| 436 | |
[email protected] | da58f5b1 | 2010-11-10 19:31:12 | [diff] [blame] | 437 | void BackgroundContentsService::LoadBackgroundContents( |
[email protected] | 1e0fe282 | 2010-06-24 21:04:19 | [diff] [blame] | 438 | Profile* profile, |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 439 | const GURL& url, |
| 440 | const string16& frame_name, |
| 441 | const string16& application_id) { |
| 442 | // We are depending on the fact that we will initialize before any user |
| 443 | // actions or session restore can take place, so no BackgroundContents should |
| 444 | // be running yet for the passed application_id. |
| 445 | DCHECK(!GetAppBackgroundContents(application_id)); |
[email protected] | 1e0fe282 | 2010-06-24 21:04:19 | [diff] [blame] | 446 | DCHECK(!application_id.empty()); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 447 | DCHECK(url.is_valid()); |
[email protected] | 8e96e50 | 2010-10-21 20:57:12 | [diff] [blame] | 448 | DVLOG(1) << "Loading background content url: " << url; |
[email protected] | 1e0fe282 | 2010-06-24 21:04:19 | [diff] [blame] | 449 | |
[email protected] | da58f5b1 | 2010-11-10 19:31:12 | [diff] [blame] | 450 | BackgroundContents* contents = CreateBackgroundContents( |
[email protected] | bc09387 | 2010-08-16 21:49:08 | [diff] [blame] | 451 | SiteInstance::CreateSiteInstanceForURL(profile, url), |
| 452 | MSG_ROUTING_NONE, |
[email protected] | da58f5b1 | 2010-11-10 19:31:12 | [diff] [blame] | 453 | profile, |
| 454 | frame_name, |
| 455 | application_id); |
[email protected] | 1e0fe282 | 2010-06-24 21:04:19 | [diff] [blame] | 456 | |
[email protected] | 1e0fe282 | 2010-06-24 21:04:19 | [diff] [blame] | 457 | // TODO(atwilson): Create RenderViews asynchronously to avoid increasing |
| 458 | // startup latency (http://crbug.com/47236). |
[email protected] | 4b19ea5 | 2012-01-02 20:15:25 | [diff] [blame] | 459 | contents->web_contents()->GetController().LoadURL( |
[email protected] | 95dacd0 | 2011-12-05 10:35:26 | [diff] [blame] | 460 | url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 461 | } |
| 462 | |
[email protected] | da58f5b1 | 2010-11-10 19:31:12 | [diff] [blame] | 463 | BackgroundContents* BackgroundContentsService::CreateBackgroundContents( |
| 464 | SiteInstance* site, |
| 465 | int routing_id, |
| 466 | Profile* profile, |
| 467 | const string16& frame_name, |
| 468 | const string16& application_id) { |
| 469 | BackgroundContents* contents = new BackgroundContents(site, routing_id, this); |
| 470 | |
| 471 | // Register the BackgroundContents internally, then send out a notification |
| 472 | // to external listeners. |
| 473 | BackgroundContentsOpenedDetails details = {contents, |
| 474 | frame_name, |
| 475 | application_id}; |
| 476 | BackgroundContentsOpened(&details); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 477 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 478 | chrome::NOTIFICATION_BACKGROUND_CONTENTS_OPENED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 479 | content::Source<Profile>(profile), |
| 480 | content::Details<BackgroundContentsOpenedDetails>(&details)); |
[email protected] | da58f5b1 | 2010-11-10 19:31:12 | [diff] [blame] | 481 | return contents; |
| 482 | } |
| 483 | |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 484 | void BackgroundContentsService::RegisterBackgroundContents( |
| 485 | BackgroundContents* background_contents) { |
| 486 | DCHECK(IsTracked(background_contents)); |
| 487 | if (!prefs_) |
| 488 | return; |
| 489 | |
| 490 | // We store the first URL we receive for a given application. If there's |
| 491 | // already an entry for this application, no need to do anything. |
[email protected] | 1e0fe282 | 2010-06-24 21:04:19 | [diff] [blame] | 492 | // TODO(atwilson): Verify that this is the desired behavior based on developer |
| 493 | // feedback (http://crbug.com/47118). |
[email protected] | f33bee5 | 2011-03-31 09:18:43 | [diff] [blame] | 494 | DictionaryPrefUpdate update(prefs_, prefs::kRegisteredBackgroundContents); |
| 495 | DictionaryValue* pref = update.Get(); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 496 | const string16& appid = GetParentApplicationId(background_contents); |
| 497 | DictionaryValue* current; |
[email protected] | 9001854 | 2010-08-14 01:49:14 | [diff] [blame] | 498 | if (pref->GetDictionaryWithoutPathExpansion(UTF16ToUTF8(appid), ¤t)) |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 499 | return; |
| 500 | |
| 501 | // No entry for this application yet, so add one. |
| 502 | DictionaryValue* dict = new DictionaryValue(); |
| 503 | dict->SetString(kUrlKey, background_contents->GetURL().spec()); |
[email protected] | ff4c1d8 | 2010-08-04 16:58:12 | [diff] [blame] | 504 | dict->SetString(kFrameNameKey, contents_map_[appid].frame_name); |
[email protected] | 8b6e84a | 2010-08-14 03:32:17 | [diff] [blame] | 505 | pref->SetWithoutPathExpansion(UTF16ToUTF8(appid), dict); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | void BackgroundContentsService::UnregisterBackgroundContents( |
| 509 | BackgroundContents* background_contents) { |
| 510 | if (!prefs_) |
| 511 | return; |
| 512 | DCHECK(IsTracked(background_contents)); |
| 513 | const string16 appid = GetParentApplicationId(background_contents); |
[email protected] | f33bee5 | 2011-03-31 09:18:43 | [diff] [blame] | 514 | DictionaryPrefUpdate update(prefs_, prefs::kRegisteredBackgroundContents); |
| 515 | update.Get()->RemoveWithoutPathExpansion(UTF16ToUTF8(appid), NULL); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | void BackgroundContentsService::ShutdownAssociatedBackgroundContents( |
| 519 | const string16& appid) { |
| 520 | BackgroundContents* contents = GetAppBackgroundContents(appid); |
| 521 | if (contents) { |
| 522 | UnregisterBackgroundContents(contents); |
| 523 | // Background contents destructor shuts down the renderer. |
| 524 | delete contents; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | void BackgroundContentsService::BackgroundContentsOpened( |
| 529 | BackgroundContentsOpenedDetails* details) { |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 530 | // Add the passed object to our list. Should not already be tracked. |
| 531 | DCHECK(!IsTracked(details->contents)); |
| 532 | DCHECK(!details->application_id.empty()); |
| 533 | contents_map_[details->application_id].contents = details->contents; |
| 534 | contents_map_[details->application_id].frame_name = details->frame_name; |
[email protected] | aa4e5ad4 | 2011-05-18 04:56:35 | [diff] [blame] | 535 | |
| 536 | ScheduleCloseBalloon(UTF16ToASCII(details->application_id)); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | // Used by test code and debug checks to verify whether a given |
| 540 | // BackgroundContents is being tracked by this instance. |
| 541 | bool BackgroundContentsService::IsTracked( |
| 542 | BackgroundContents* background_contents) const { |
| 543 | return !GetParentApplicationId(background_contents).empty(); |
| 544 | } |
| 545 | |
| 546 | void BackgroundContentsService::BackgroundContentsShutdown( |
| 547 | BackgroundContents* background_contents) { |
| 548 | // Remove the passed object from our list. |
| 549 | DCHECK(IsTracked(background_contents)); |
| 550 | string16 appid = GetParentApplicationId(background_contents); |
| 551 | contents_map_.erase(appid); |
[email protected] | 398206c | 2010-06-21 01:46:08 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | BackgroundContents* BackgroundContentsService::GetAppBackgroundContents( |
| 555 | const string16& application_id) { |
| 556 | BackgroundContentsMap::const_iterator it = contents_map_.find(application_id); |
| 557 | return (it != contents_map_.end()) ? it->second.contents : NULL; |
| 558 | } |
| 559 | |
| 560 | const string16& BackgroundContentsService::GetParentApplicationId( |
| 561 | BackgroundContents* contents) const { |
| 562 | for (BackgroundContentsMap::const_iterator it = contents_map_.begin(); |
| 563 | it != contents_map_.end(); ++it) { |
| 564 | if (contents == it->second.contents) |
| 565 | return it->first; |
| 566 | } |
| 567 | return EmptyString16(); |
| 568 | } |
| 569 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 570 | void BackgroundContentsService::AddWebContents( |
| 571 | WebContents* new_contents, |
[email protected] | bc09387 | 2010-08-16 21:49:08 | [diff] [blame] | 572 | WindowOpenDisposition disposition, |
| 573 | const gfx::Rect& initial_pos, |
| 574 | bool user_gesture) { |
| 575 | Browser* browser = BrowserList::GetLastActiveWithProfile( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 576 | Profile::FromBrowserContext(new_contents->GetBrowserContext())); |
[email protected] | bc09387 | 2010-08-16 21:49:08 | [diff] [blame] | 577 | if (!browser) |
| 578 | return; |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 579 | browser->AddWebContents(new_contents, disposition, initial_pos, user_gesture); |
[email protected] | bc09387 | 2010-08-16 21:49:08 | [diff] [blame] | 580 | } |