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

Side by Side Diff: chrome/browser/extensions/extension_function_dispatcher.cc

Issue 3210007: Add support for a "split" incognito behavior for extensions. (Closed)
Patch Set: latest Created 10 years, 3 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/extensions/extension_function_dispatcher.h" 5 #include "chrome/browser/extensions/extension_function_dispatcher.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/singleton.h" 10 #include "base/singleton.h"
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } 376 }
377 377
378 // Update the extension permissions. Doing this each time we create an EFD 378 // Update the extension permissions. Doing this each time we create an EFD
379 // ensures that new processes are informed of permissions for newly installed 379 // ensures that new processes are informed of permissions for newly installed
380 // extensions. 380 // extensions.
381 render_view_host->Send(new ViewMsg_Extension_SetAPIPermissions( 381 render_view_host->Send(new ViewMsg_Extension_SetAPIPermissions(
382 extension->id(), extension->api_permissions())); 382 extension->id(), extension->api_permissions()));
383 render_view_host->Send(new ViewMsg_Extension_SetHostPermissions( 383 render_view_host->Send(new ViewMsg_Extension_SetHostPermissions(
384 extension->url(), extension->host_permissions())); 384 extension->url(), extension->host_permissions()));
385 render_view_host->Send(new ViewMsg_Extension_ExtensionSetIncognitoEnabled( 385 render_view_host->Send(new ViewMsg_Extension_ExtensionSetIncognitoEnabled(
386 extension->id(), incognito_enabled)); 386 extension->id(), incognito_enabled, extension->incognito_split_mode()));
387 387
388 NotificationService::current()->Notify( 388 NotificationService::current()->Notify(
389 NotificationType::EXTENSION_FUNCTION_DISPATCHER_CREATED, 389 NotificationType::EXTENSION_FUNCTION_DISPATCHER_CREATED,
390 Source<Profile>(profile_), 390 Source<Profile>(profile_),
391 Details<ExtensionFunctionDispatcher>(this)); 391 Details<ExtensionFunctionDispatcher>(this));
392 } 392 }
393 393
394 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() { 394 ExtensionFunctionDispatcher::~ExtensionFunctionDispatcher() {
395 peer_->dispatcher_ = NULL; 395 peer_->dispatcher_ = NULL;
396 396
397 NotificationService::current()->Notify( 397 NotificationService::current()->Notify(
398 NotificationType::EXTENSION_FUNCTION_DISPATCHER_DESTROYED, 398 NotificationType::EXTENSION_FUNCTION_DISPATCHER_DESTROYED,
399 Source<Profile>(profile_), 399 Source<Profile>(profile_),
400 Details<ExtensionFunctionDispatcher>(this)); 400 Details<ExtensionFunctionDispatcher>(this));
401 } 401 }
402 402
403 Browser* ExtensionFunctionDispatcher::GetCurrentBrowser( 403 Browser* ExtensionFunctionDispatcher::GetCurrentBrowser(
404 bool include_incognito) { 404 bool include_incognito) {
405 Browser* browser = delegate_->GetBrowser(); 405 Browser* browser = delegate_->GetBrowser();
406 406
407 // If the delegate has an associated browser and that browser is in the right 407 // If the delegate has an associated browser, that is always the right answer.
408 // incognito state, we can return it. 408 if (browser)
409 if (browser) { 409 return browser;
410 if (include_incognito || !browser->profile()->IsOffTheRecord())
411 return browser;
412 }
413 410
414 // Otherwise, try to default to a reasonable browser. 411 // Otherwise, try to default to a reasonable browser. If |include_incognito|
412 // is true, we will also search browsers in the incognito version of this
413 // profile. Note that the profile may already be incognito, in which case
414 // we will search the incognito version only, regardless of the value of
415 // |include_incognito|.
415 Profile* profile = render_view_host()->process()->profile(); 416 Profile* profile = render_view_host()->process()->profile();
416
417 // Make sure we don't return an incognito browser without proper access.
418 if (!include_incognito)
419 profile = profile->GetOriginalProfile();
420
421 browser = BrowserList::FindBrowserWithType(profile, Browser::TYPE_NORMAL, 417 browser = BrowserList::FindBrowserWithType(profile, Browser::TYPE_NORMAL,
422 include_incognito); 418 include_incognito);
423 419
424 // NOTE(rafaelw): This can return NULL in some circumstances. In particular, 420 // NOTE(rafaelw): This can return NULL in some circumstances. In particular,
425 // a background_page onload chrome.tabs api call can make it into here 421 // a background_page onload chrome.tabs api call can make it into here
426 // before the browser is sufficiently initialized to return here. 422 // before the browser is sufficiently initialized to return here.
427 // A similar situation may arise during shutdown. 423 // A similar situation may arise during shutdown.
428 // TODO(rafaelw): Delay creation of background_page until the browser 424 // TODO(rafaelw): Delay creation of background_page until the browser
429 // is available. http://code.google.com/p/chromium/issues/detail?id=13284 425 // is available. http://code.google.com/p/chromium/issues/detail?id=13284
430 return browser; 426 return browser;
431 } 427 }
432 428
433 void ExtensionFunctionDispatcher::HandleRequest( 429 void ExtensionFunctionDispatcher::HandleRequest(
434 const ViewHostMsg_DomMessage_Params& params) { 430 const ViewHostMsg_DomMessage_Params& params) {
435 scoped_refptr<ExtensionFunction> function( 431 scoped_refptr<ExtensionFunction> function(
436 FactoryRegistry::instance()->NewFunction(params.name)); 432 FactoryRegistry::instance()->NewFunction(params.name));
437 function->set_dispatcher_peer(peer_); 433 function->set_dispatcher_peer(peer_);
438 function->set_profile(profile_); 434 function->set_profile(profile_);
439 function->set_extension_id(extension_id()); 435 function->set_extension_id(extension_id());
440 function->SetArgs(&params.arguments); 436 function->SetArgs(&params.arguments);
441 function->set_source_url(params.source_url); 437 function->set_source_url(params.source_url);
442 function->set_request_id(params.request_id); 438 function->set_request_id(params.request_id);
443 function->set_has_callback(params.has_callback); 439 function->set_has_callback(params.has_callback);
444 function->set_user_gesture(params.user_gesture); 440 function->set_user_gesture(params.user_gesture);
445 ExtensionsService* service = profile()->GetExtensionsService(); 441 ExtensionsService* service = profile()->GetExtensionsService();
446 DCHECK(service); 442 DCHECK(service);
447 Extension* extension = service->GetExtensionById(extension_id(), false); 443 Extension* extension = service->GetExtensionById(extension_id(), false);
448 DCHECK(extension); 444 DCHECK(extension);
449 function->set_include_incognito(service->IsIncognitoEnabled(extension)); 445 function->set_include_incognito(service->IsIncognitoEnabled(extension) &&
446 !extension->incognito_split_mode());
450 447
451 ExtensionsQuotaService* quota = service->quota_service(); 448 ExtensionsQuotaService* quota = service->quota_service();
452 if (quota->Assess(extension_id(), function, &params.arguments, 449 if (quota->Assess(extension_id(), function, &params.arguments,
453 base::TimeTicks::Now())) { 450 base::TimeTicks::Now())) {
454 // See crbug.com/39178. 451 // See crbug.com/39178.
455 ExternalProtocolHandler::PermitLaunchUrl(); 452 ExternalProtocolHandler::PermitLaunchUrl();
456 453
457 function->Run(); 454 function->Run();
458 } else { 455 } else {
459 render_view_host_->SendExtensionResponse(function->request_id(), false, 456 render_view_host_->SendExtensionResponse(function->request_id(), false,
(...skipping 17 matching lines...) Expand all
477 } else { 474 } else {
478 NOTREACHED(); 475 NOTREACHED();
479 base::KillProcess(render_view_host_->process()->GetHandle(), 476 base::KillProcess(render_view_host_->process()->GetHandle(),
480 ResultCodes::KILLED_BAD_MESSAGE, false); 477 ResultCodes::KILLED_BAD_MESSAGE, false);
481 } 478 }
482 } 479 }
483 480
484 Profile* ExtensionFunctionDispatcher::profile() { 481 Profile* ExtensionFunctionDispatcher::profile() {
485 return profile_; 482 return profile_;
486 } 483 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_function.h ('k') | chrome/browser/extensions/extension_history_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698