Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: chrome/browser/background/background_contents_service.cc

Issue 9150008: Introduce background.scripts feature for extension manifests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ready to land Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/background/background_contents_service.h" 5 #include "chrome/browser/background/background_contents_service.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // background page. 232 // background page.
233 BackgroundContents* bgcontents = 233 BackgroundContents* bgcontents =
234 content::Details<BackgroundContents>(details).ptr(); 234 content::Details<BackgroundContents>(details).ptr();
235 Profile* profile = content::Source<Profile>(source).ptr(); 235 Profile* profile = content::Source<Profile>(source).ptr();
236 const string16& appid = GetParentApplicationId(bgcontents); 236 const string16& appid = GetParentApplicationId(bgcontents);
237 ExtensionService* extension_service = profile->GetExtensionService(); 237 ExtensionService* extension_service = profile->GetExtensionService();
238 // extension_service can be NULL when running tests. 238 // extension_service can be NULL when running tests.
239 if (extension_service) { 239 if (extension_service) {
240 const Extension* extension = 240 const Extension* extension =
241 extension_service->GetExtensionById(UTF16ToUTF8(appid), false); 241 extension_service->GetExtensionById(UTF16ToUTF8(appid), false);
242 if (extension && extension->background_url().is_valid()) 242 if (extension && extension->has_background_page())
243 break; 243 break;
244 } 244 }
245 RegisterBackgroundContents(bgcontents); 245 RegisterBackgroundContents(bgcontents);
246 break; 246 break;
247 } 247 }
248 case chrome::NOTIFICATION_EXTENSION_LOADED: { 248 case chrome::NOTIFICATION_EXTENSION_LOADED: {
249 const Extension* extension = 249 const Extension* extension =
250 content::Details<const Extension>(details).ptr(); 250 content::Details<const Extension>(details).ptr();
251 Profile* profile = content::Source<Profile>(source).ptr(); 251 Profile* profile = content::Source<Profile>(source).ptr();
252 if (extension->is_hosted_app() && 252 if (extension->is_hosted_app() &&
253 extension->background_url().is_valid()) { 253 extension->has_background_page()) {
254 // If there is a background page specified in the manifest for a hosted 254 // If there is a background page specified in the manifest for a hosted
255 // app, then blow away registered urls in the pref. 255 // app, then blow away registered urls in the pref.
256 ShutdownAssociatedBackgroundContents(ASCIIToUTF16(extension->id())); 256 ShutdownAssociatedBackgroundContents(ASCIIToUTF16(extension->id()));
257 257
258 ExtensionService* service = profile->GetExtensionService(); 258 ExtensionService* service = profile->GetExtensionService();
259 if (service && service->is_ready()) { 259 if (service && service->is_ready()) {
260 // Now load the manifest-specified background page. If service isn't 260 // Now load the manifest-specified background page. If service isn't
261 // ready, then the background page will be loaded from the 261 // ready, then the background page will be loaded from the
262 // EXTENSIONS_READY callback. 262 // EXTENSIONS_READY callback.
263 LoadBackgroundContents(profile, extension->background_url(), 263 LoadBackgroundContents(profile, extension->GetBackgroundURL(),
264 ASCIIToUTF16("background"), UTF8ToUTF16(extension->id())); 264 ASCIIToUTF16("background"), UTF8ToUTF16(extension->id()));
265 } 265 }
266 } 266 }
267 267
268 // Remove any "This extension has crashed" balloons. 268 // Remove any "This extension has crashed" balloons.
269 ScheduleCloseBalloon(extension->id()); 269 ScheduleCloseBalloon(extension->id());
270 break; 270 break;
271 } 271 }
272 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: 272 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED:
273 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED: { 273 case chrome::NOTIFICATION_BACKGROUND_CONTENTS_TERMINATED: {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> 307 ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)->
308 extension->id())); 308 extension->id()));
309 break; 309 break;
310 case extension_misc::UNLOAD_REASON_UPDATE: { 310 case extension_misc::UNLOAD_REASON_UPDATE: {
311 // If there is a manifest specified background page, then shut it down 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, 312 // here, since if the updated extension still has the background page,
313 // then it will be loaded from LOADED callback. Otherwise, leave 313 // then it will be loaded from LOADED callback. Otherwise, leave
314 // BackgroundContents in place. 314 // BackgroundContents in place.
315 const Extension* extension = 315 const Extension* extension =
316 content::Details<UnloadedExtensionInfo>(details)->extension; 316 content::Details<UnloadedExtensionInfo>(details)->extension;
317 if (extension->background_url().is_valid()) 317 if (extension->has_background_page())
318 ShutdownAssociatedBackgroundContents(ASCIIToUTF16(extension->id())); 318 ShutdownAssociatedBackgroundContents(ASCIIToUTF16(extension->id()));
319 break; 319 break;
320 } 320 }
321 default: 321 default:
322 NOTREACHED(); 322 NOTREACHED();
323 ShutdownAssociatedBackgroundContents( 323 ShutdownAssociatedBackgroundContents(
324 ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)-> 324 ASCIIToUTF16(content::Details<UnloadedExtensionInfo>(details)->
325 extension->id())); 325 extension->id()));
326 break; 326 break;
327 } 327 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 371 }
372 } 372 }
373 373
374 void BackgroundContentsService::LoadBackgroundContentsForExtension( 374 void BackgroundContentsService::LoadBackgroundContentsForExtension(
375 Profile* profile, 375 Profile* profile,
376 const std::string& extension_id) { 376 const std::string& extension_id) {
377 // First look if the manifest specifies a background page. 377 // First look if the manifest specifies a background page.
378 const Extension* extension = 378 const Extension* extension =
379 profile->GetExtensionService()->GetExtensionById(extension_id, false); 379 profile->GetExtensionService()->GetExtensionById(extension_id, false);
380 DCHECK(!extension || extension->is_hosted_app()); 380 DCHECK(!extension || extension->is_hosted_app());
381 if (extension && extension->background_url().is_valid()) { 381 if (extension && extension->has_background_page()) {
382 LoadBackgroundContents(profile, 382 LoadBackgroundContents(profile,
383 extension->background_url(), 383 extension->GetBackgroundURL(),
384 ASCIIToUTF16("background"), 384 ASCIIToUTF16("background"),
385 UTF8ToUTF16(extension->id())); 385 UTF8ToUTF16(extension->id()));
386 return; 386 return;
387 } 387 }
388 388
389 // Now look in the prefs. 389 // Now look in the prefs.
390 if (!prefs_) 390 if (!prefs_)
391 return; 391 return;
392 const DictionaryValue* contents = 392 const DictionaryValue* contents =
393 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); 393 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents);
(...skipping 24 matching lines...) Expand all
418 UTF8ToUTF16(extension_id)); 418 UTF8ToUTF16(extension_id));
419 } 419 }
420 420
421 void BackgroundContentsService::LoadBackgroundContentsFromManifests( 421 void BackgroundContentsService::LoadBackgroundContentsFromManifests(
422 Profile* profile) { 422 Profile* profile) {
423 const ExtensionSet* extensions = 423 const ExtensionSet* extensions =
424 profile->GetExtensionService()->extensions(); 424 profile->GetExtensionService()->extensions();
425 ExtensionSet::const_iterator iter = extensions->begin(); 425 ExtensionSet::const_iterator iter = extensions->begin();
426 for (; iter != extensions->end(); ++iter) { 426 for (; iter != extensions->end(); ++iter) {
427 const Extension* extension = *iter; 427 const Extension* extension = *iter;
428 if (extension->is_hosted_app() && 428 if (extension->is_hosted_app() && extension->has_background_page()) {
429 extension->background_url().is_valid()) {
430 LoadBackgroundContents(profile, 429 LoadBackgroundContents(profile,
431 extension->background_url(), 430 extension->GetBackgroundURL(),
432 ASCIIToUTF16("background"), 431 ASCIIToUTF16("background"),
433 UTF8ToUTF16(extension->id())); 432 UTF8ToUTF16(extension->id()));
434 } 433 }
435 } 434 }
436 } 435 }
437 436
438 void BackgroundContentsService::LoadBackgroundContents( 437 void BackgroundContentsService::LoadBackgroundContents(
439 Profile* profile, 438 Profile* profile,
440 const GURL& url, 439 const GURL& url,
441 const string16& frame_name, 440 const string16& frame_name,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 WebContents* new_contents, 571 WebContents* new_contents,
573 WindowOpenDisposition disposition, 572 WindowOpenDisposition disposition,
574 const gfx::Rect& initial_pos, 573 const gfx::Rect& initial_pos,
575 bool user_gesture) { 574 bool user_gesture) {
576 Browser* browser = BrowserList::GetLastActiveWithProfile( 575 Browser* browser = BrowserList::GetLastActiveWithProfile(
577 Profile::FromBrowserContext(new_contents->GetBrowserContext())); 576 Profile::FromBrowserContext(new_contents->GetBrowserContext()));
578 if (!browser) 577 if (!browser)
579 return; 578 return;
580 browser->AddWebContents(new_contents, disposition, initial_pos, user_gesture); 579 browser->AddWebContents(new_contents, disposition, initial_pos, user_gesture);
581 } 580 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.cc ('k') | chrome/browser/extensions/background_scripts_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698