Add the concept of browse extent.

BUG=46636

Review URL: http://codereview.chromium.org/2862034

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51327 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index a4fc69df..97c0870 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -3606,6 +3606,11 @@
   if (source_extension == destination_extension)
     return false;
 
+  // If there is a source extension and the new URL is part of its browse
+  // extent, also do nothing.
+  if (source_extension && source_extension->browse_extent().ContainsURL(url))
+    return false;
+
   if (destination_extension) {
     // Search for an existing app window for this app.
     for (BrowserList::const_iterator iter = BrowserList::begin();
diff --git a/chrome/browser/extensions/app_process_apitest.cc b/chrome/browser/extensions/app_process_apitest.cc
index 99bfa9d..7cdc80b 100644
--- a/chrome/browser/extensions/app_process_apitest.cc
+++ b/chrome/browser/extensions/app_process_apitest.cc
@@ -107,4 +107,16 @@
             browser()->GetTabContentsAt(1)->render_view_host()->process());
   EXPECT_EQ(host->render_process_host(),
             browser()->GetTabContentsAt(3)->render_view_host()->process());
+
+  // Navigate the non-app tab into the browse extent. It should not enter the
+  // app process.
+  // Navigate the app tab into the browse extent. It should stay in the app
+  // process.
+  const GURL& browse_url(base_url.Resolve("path4/empty.html"));
+  NavigateTabHelper(browser()->GetTabContentsAt(1), browse_url);
+  NavigateTabHelper(browser()->GetTabContentsAt(3), browse_url);
+  EXPECT_NE(host->render_process_host(),
+            browser()->GetTabContentsAt(1)->render_view_host()->process());
+  EXPECT_EQ(host->render_process_host(),
+            browser()->GetTabContentsAt(3)->render_view_host()->process());
 }
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 6518b6f..81c56f3 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -455,7 +455,7 @@
             *static_cast<DictionaryValue*>(manifest.get()),
             true,  // require key
             &error)) {
-      NOTREACHED();
+      NOTREACHED() << error;
       return;
     }
 
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index 38b8b01..1afe34a3 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -665,8 +665,11 @@
   for (size_t i = 0; i < service->extensions()->size(); ++i) {
     Extension* extension = service->extensions()->at(i);
     if (!extension->web_extent().is_empty()) {
-      params.extension_apps.push_back(
-          make_pair(extension->id(), extension->web_extent()));
+      ViewMsg_ExtensionExtentInfo info;
+      info.extension_id = extension->id();
+      info.web_extent = extension->web_extent();
+      info.browse_extent = extension->browse_extent();
+      params.extension_apps.push_back(info);
     }
   }
 
diff --git a/chrome/browser/resources/calendar_app/manifest.json b/chrome/browser/resources/calendar_app/manifest.json
index df388fa..8bcf843 100644
--- a/chrome/browser/resources/calendar_app/manifest.json
+++ b/chrome/browser/resources/calendar_app/manifest.json
@@ -13,6 +13,9 @@
     "urls": [
       "*://www.google.com/calendar/"
     ],
+    "browse_urls": [
+      "https://www.google.com/accounts/"
+    ],
     "launch": {
       "container": "tab",
       "web_url": "https://www.google.com/calendar/"
diff --git a/chrome/browser/resources/docs_app/manifest.json b/chrome/browser/resources/docs_app/manifest.json
index 1df3c5c6..10e965c 100644
--- a/chrome/browser/resources/docs_app/manifest.json
+++ b/chrome/browser/resources/docs_app/manifest.json
@@ -34,6 +34,9 @@
       "*://spreadsheets8.google.com/",
       "*://spreadsheets9.google.com/"
     ],
+    "browse_urls": [
+      "https://www.google.com/accounts/"
+    ],
     "launch": {
       "web_url": "https://docs.google.com/"
     }
diff --git a/chrome/browser/resources/gmail_app/manifest.json b/chrome/browser/resources/gmail_app/manifest.json
index 4a90be2..9dfcf98 100644
--- a/chrome/browser/resources/gmail_app/manifest.json
+++ b/chrome/browser/resources/gmail_app/manifest.json
@@ -15,6 +15,9 @@
       "*://gmail.com/",
       "*://www.gmail.com/"
     ],
+    "browse_urls": [
+      "https://www.google.com/accounts/"
+    ],
     "launch": {
       "web_url": "https://mail.google.com/mail/"
     }