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

Side by Side Diff: chrome/browser/chrome_content_browser_client.cc

Issue 11234032: Webview tag creation should be using storage partitions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removing the custom format of partition id. Created 8 years, 1 month 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/string_split.h"
14 #include "base/string_tokenizer.h" 15 #include "base/string_tokenizer.h"
15 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
16 #include "chrome/app/breakpad_mac.h" 17 #include "chrome/app/breakpad_mac.h"
17 #include "chrome/browser/browser_about_handler.h" 18 #include "chrome/browser/browser_about_handler.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/browsing_data/browsing_data_helper.h" 20 #include "chrome/browser/browsing_data/browsing_data_helper.h"
20 #include "chrome/browser/browsing_data/browsing_data_remover.h" 21 #include "chrome/browser/browsing_data/browsing_data_remover.h"
21 #include "chrome/browser/character_encoding.h" 22 #include "chrome/browser/character_encoding.h"
22 #include "chrome/browser/chrome_benchmarking_message_filter.h" 23 #include "chrome/browser/chrome_benchmarking_message_filter.h"
23 #include "chrome/browser/chrome_quota_permission_context.h" 24 #include "chrome/browser/chrome_quota_permission_context.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 #include "content/public/browser/render_process_host.h" 95 #include "content/public/browser/render_process_host.h"
95 #include "content/public/browser/render_view_host.h" 96 #include "content/public/browser/render_view_host.h"
96 #include "content/public/browser/resource_context.h" 97 #include "content/public/browser/resource_context.h"
97 #include "content/public/browser/site_instance.h" 98 #include "content/public/browser/site_instance.h"
98 #include "content/public/browser/web_contents.h" 99 #include "content/public/browser/web_contents.h"
99 #include "content/public/browser/web_contents_view.h" 100 #include "content/public/browser/web_contents_view.h"
100 #include "content/public/common/child_process_host.h" 101 #include "content/public/common/child_process_host.h"
101 #include "content/public/common/content_descriptors.h" 102 #include "content/public/common/content_descriptors.h"
102 #include "grit/generated_resources.h" 103 #include "grit/generated_resources.h"
103 #include "grit/ui_resources.h" 104 #include "grit/ui_resources.h"
105 #include "net/base/escape.h"
104 #include "net/base/ssl_cert_request_info.h" 106 #include "net/base/ssl_cert_request_info.h"
105 #include "net/cookies/canonical_cookie.h" 107 #include "net/cookies/canonical_cookie.h"
106 #include "net/cookies/cookie_options.h" 108 #include "net/cookies/cookie_options.h"
107 #include "ppapi/host/ppapi_host.h" 109 #include "ppapi/host/ppapi_host.h"
108 #include "ui/base/l10n/l10n_util.h" 110 #include "ui/base/l10n/l10n_util.h"
109 #include "ui/base/resource/resource_bundle.h" 111 #include "ui/base/resource/resource_bundle.h"
110 #include "webkit/glue/webpreferences.h" 112 #include "webkit/glue/webpreferences.h"
111 #include "webkit/plugins/plugin_switches.h" 113 #include "webkit/plugins/plugin_switches.h"
112 114
113 #if defined(OS_WIN) 115 #if defined(OS_WIN)
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 return main_parts; 464 return main_parts;
463 } 465 }
464 466
465 content::WebContentsView* 467 content::WebContentsView*
466 ChromeContentBrowserClient::OverrideCreateWebContentsView( 468 ChromeContentBrowserClient::OverrideCreateWebContentsView(
467 WebContents* web_contents, 469 WebContents* web_contents,
468 content::RenderViewHostDelegateView** render_view_host_delegate_view) { 470 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
469 return NULL; 471 return NULL;
470 } 472 }
471 473
472 std::string ChromeContentBrowserClient::GetStoragePartitionIdForChildProcess(
473 content::BrowserContext* browser_context,
474 int child_process_id) {
475 const Extension* extension = NULL;
476 Profile* profile = Profile::FromBrowserContext(browser_context);
477 ExtensionService* extension_service =
478 extensions::ExtensionSystem::Get(profile)->extension_service();
479 if (extension_service) {
480 std::set<std::string> extension_ids =
481 extension_service->process_map()->
482 GetExtensionsInProcess(child_process_id);
483 if (!extension_ids.empty())
484 // Since All the apps in a process share the same storage partition,
485 // we can pick any of them to retrieve the storage partition id.
486 extension =
487 extension_service->extensions()->GetByID(*(extension_ids.begin()));
488 }
489 return GetStoragePartitionIdForExtension(browser_context, extension);
490 }
491
492 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( 474 std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
493 content::BrowserContext* browser_context, 475 content::BrowserContext* browser_context,
494 const GURL& site) { 476 const GURL& site) {
477 std::string partition_id;
478
479 if (site.SchemeIs(chrome::kGuestScheme)) {
Charlie Reis 2012/11/07 02:36:34 Can you give example(s) in a comment? This looks
nasko 2012/11/07 17:47:01 Done.
480 partition_id = site.spec();
481 }
482
483 DCHECK(IsValidStoragePartitionId(browser_context,partition_id));
484 return partition_id;
485 }
486
487 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
488 content::BrowserContext* browser_context,
489 const std::string& partition_id) {
490 // The default ID is empty and is always valid.
491 if (partition_id.empty())
492 return true;
493
494 GURL guest_url(partition_id);
495
496 return guest_url.is_valid();
497 }
498
499 void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
500 content::BrowserContext* browser_context,
501 const GURL& site,
502 std::string* app_id,
Charlie Reis 2012/11/07 02:36:34 Please leave this as partition_domain. Coding sty
nasko 2012/11/07 17:47:01 Done.
503 std::string* partition_name,
504 bool* in_memory) {
505 // For the webview tag, we create special guest processes, which host the
506 // tag content separately from the main application that embeds the tag.
507 // A webview tag can specify both the partition name and whether the storage
508 // for that partition should be persisted. Each tag gets a SiteInstance with
509 // a specially formatted URL, based on the application it is hosted by and
510 // the partition requested by it. The format for that URL is:
511 // guest://app_id/persist?partition_name
Charlie Reis 2012/11/07 02:36:34 Awesome comment! nit: chrome-guest://
nasko 2012/11/07 17:47:01 Done.
512 if (site.SchemeIs(chrome::kGuestScheme)) {
513 // Since guest URLs are only used for packaged apps, there must be an app
514 // id in the URL.
515 CHECK(site.has_host());
516 *app_id = site.host();
517 // Since persistence is optional, the path must either be empty or the
518 // literal string.
519 *in_memory = (site.path() != "/persist");
520 // The partition name is user supplied value, which we have encoded when the
521 // URL was created, so it needs to be decoded.
522 *partition_name = net::UnescapeURLComponent(site.query(),
523 net::UnescapeRule::NORMAL);
524 return;
525 }
526
495 const Extension* extension = NULL; 527 const Extension* extension = NULL;
496 Profile* profile = Profile::FromBrowserContext(browser_context); 528 Profile* profile = Profile::FromBrowserContext(browser_context);
497 ExtensionService* extension_service = 529 ExtensionService* extension_service =
498 extensions::ExtensionSystem::Get(profile)->extension_service(); 530 extensions::ExtensionSystem::Get(profile)->extension_service();
499 if (extension_service) { 531 if (extension_service) {
500 extension = extension_service->extensions()-> 532 extension = extension_service->extensions()->
501 GetExtensionOrAppByURL(ExtensionURLInfo(site)); 533 GetExtensionOrAppByURL(ExtensionURLInfo(site));
534 if (extension && extension->is_storage_isolated()) {
Charlie Reis 2012/11/07 02:36:34 Please add a comment here saying that storage-isol
nasko 2012/11/07 17:47:01 Done.
535 *app_id = extension->id();
536 partition_name->clear();
537 *in_memory = false;
538 return;
539 }
502 } 540 }
503 541
504 return GetStoragePartitionIdForExtension(browser_context, extension); 542 app_id->clear();
Charlie Reis 2012/11/07 02:36:34 Add a comment here saying that all other cases use
nasko 2012/11/07 17:47:01 Done.
505 } 543 partition_name->clear();
506 544 *in_memory = false;
507 bool ChromeContentBrowserClient::IsValidStoragePartitionId(
508 content::BrowserContext* browser_context,
509 const std::string& partition_id) {
510 // The default ID is empty which is always allowed.
511 if (partition_id.empty())
512 return true;
513
514 // If it isn't empty, then it must belong to an extension of some sort. Parse
515 // out the extension ID and make sure it is still installed.
516 Profile* profile = Profile::FromBrowserContext(browser_context);
517 ExtensionService* extension_service =
518 extensions::ExtensionSystem::Get(profile)->extension_service();
519 if (!extension_service) {
520 // No extension service means no storage partitions in Chrome.
521 return false;
522 }
523
524 // See if we can find an extension. The |partition_id| is the extension ID so
525 // no parsing needed to be done.
526 return extension_service->GetExtensionById(partition_id, false) != NULL;
527 } 545 }
528 546
529 content::WebContentsViewDelegate* 547 content::WebContentsViewDelegate*
530 ChromeContentBrowserClient::GetWebContentsViewDelegate( 548 ChromeContentBrowserClient::GetWebContentsViewDelegate(
531 content::WebContents* web_contents) { 549 content::WebContents* web_contents) {
532 return chrome::CreateWebContentsViewDelegate(web_contents); 550 return chrome::CreateWebContentsViewDelegate(web_contents);
533 } 551 }
534 552
535 void ChromeContentBrowserClient::RenderViewHostCreated( 553 void ChromeContentBrowserClient::RenderViewHostCreated(
536 RenderViewHost* render_view_host) { 554 RenderViewHost* render_view_host) {
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 if (web_prefs->default_encoding.empty()) { 1619 if (web_prefs->default_encoding.empty()) {
1602 prefs->ClearPref(prefs::kDefaultCharset); 1620 prefs->ClearPref(prefs::kDefaultCharset);
1603 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); 1621 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
1604 } 1622 }
1605 DCHECK(!web_prefs->default_encoding.empty()); 1623 DCHECK(!web_prefs->default_encoding.empty());
1606 1624
1607 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); 1625 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1608 chrome::ViewType view_type = chrome::GetViewType(web_contents); 1626 chrome::ViewType view_type = chrome::GetViewType(web_contents);
1609 ExtensionService* service = profile->GetExtensionService(); 1627 ExtensionService* service = profile->GetExtensionService();
1610 if (service) { 1628 if (service) {
1611 const Extension* extension = service->extensions()->GetByID( 1629 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1612 rvh->GetSiteInstance()->GetSiteURL().host()); 1630 const Extension* extension = service->extensions()->GetByID(url.host());
1613 extension_webkit_preferences::SetPreferences( 1631 // Ensure that we are only granting extension preferences to URLs with
1614 extension, view_type, web_prefs); 1632 // the correct scheme. Without this check, guest:// schemes used by
Charlie Reis 2012/11/07 02:36:34 nit: chrome-guest://
nasko 2012/11/07 17:47:01 Done.
1633 // webview tags as well as hosts that happen to match the id of an
1634 // installed extension would get the wrong preferences.
1635 if (url.SchemeIs(chrome::kExtensionScheme)) {
1636 extension_webkit_preferences::SetPreferences(
1637 extension, view_type, web_prefs);
1638 }
1615 } 1639 }
1616 1640
1617 if (content::IsForceCompositingModeEnabled()) 1641 if (content::IsForceCompositingModeEnabled())
1618 web_prefs->force_compositing_mode = true; 1642 web_prefs->force_compositing_mode = true;
1619 1643
1620 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) { 1644 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
1621 web_prefs->allow_scripts_to_close_windows = true; 1645 web_prefs->allow_scripts_to_close_windows = true;
1622 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) { 1646 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1623 // Disable all kinds of acceleration for background pages. 1647 // Disable all kinds of acceleration for background pages.
1624 // See http://crbug.com/96005 and http://crbug.com/96006 1648 // See http://crbug.com/96005 and http://crbug.com/96006
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1866 base::Unretained(this), locale))) 1890 base::Unretained(this), locale)))
1867 io_thread_application_locale_ = locale; 1891 io_thread_application_locale_ = locale;
1868 } 1892 }
1869 1893
1870 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread( 1894 void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1871 const std::string& locale) { 1895 const std::string& locale) {
1872 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1896 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1873 io_thread_application_locale_ = locale; 1897 io_thread_application_locale_ = locale;
1874 } 1898 }
1875 1899
1876 std::string ChromeContentBrowserClient::GetStoragePartitionIdForExtension(
1877 content::BrowserContext* browser_context, const Extension* extension) {
1878 // In chrome, we use the extension ID as the partition ID. This works well
1879 // because the extension ID fits the partition ID pattern and currently only
1880 // apps can designate that storage should be isolated.
1881 //
1882 // If |extension| is NULL, then the default, empty string, partition id is
1883 // used.
1884 std::string partition_id;
1885 if (extension && extension->is_storage_isolated()) {
1886 partition_id = extension->id();
1887 }
1888
1889 // Enforce that IsValidStoragePartitionId() implementation stays in sync.
1890 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
1891 return partition_id;
1892 }
1893
1894
1895 } // namespace chrome 1900 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698