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

Side by Side Diff: chrome/browser/guest_view/guest_view_manager.cc

Issue 299753011: Move allocate instance id to chrome/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from fady Created 6 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/guest_view/guest_view_manager.h" 5 #include "chrome/browser/guest_view/guest_view_manager.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/guest_view/guest_view_base.h" 9 #include "chrome/browser/guest_view/guest_view_base.h"
10 #include "chrome/browser/guest_view/guest_view_constants.h" 10 #include "chrome/browser/guest_view/guest_view_constants.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/render_process_host.h" 13 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/user_metrics.h" 14 #include "content/public/browser/user_metrics.h"
15 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/common/result_codes.h" 16 #include "content/public/common/result_codes.h"
17 #include "content/public/common/url_constants.h" 17 #include "content/public/common/url_constants.h"
18 #include "extensions/browser/extension_system.h" 18 #include "extensions/browser/extension_system.h"
19 #include "net/base/escape.h" 19 #include "net/base/escape.h"
20 #include "url/gurl.h" 20 #include "url/gurl.h"
21 21
22 using content::BrowserContext; 22 using content::BrowserContext;
23 using content::SiteInstance; 23 using content::SiteInstance;
24 using content::WebContents; 24 using content::WebContents;
25 25
26 namespace {
27
28 void ParsePartitionParam(const std::string& partition_str,
Fady Samuel 2014/06/03 16:36:34 This seems like a <webview> feature. Can we move t
lazyboy 2014/06/03 19:17:58 I've moved the utility function to web_view_guest.
29 std::string* storage_partition_id,
30 bool* persist_storage) {
31 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on
32 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely
33 // remove the prefix without splicing in the middle of a multi-byte codepoint.
34 // We can use the rest of the string as UTF-8 encoded one.
35 if (StartsWithASCII(partition_str, "persist:", true)) {
36 size_t index = partition_str.find(":");
37 CHECK(index != std::string::npos);
38 // It is safe to do index + 1, since we tested for the full prefix above.
39 *storage_partition_id = partition_str.substr(index + 1);
40
41 if (storage_partition_id->empty()) {
42 // TODO(lazyboy): Better way to deal with this error.
43 return;
44 }
45 *persist_storage = true;
46 } else {
47 *storage_partition_id = partition_str;
48 *persist_storage = false;
49 }
50
51 printf("Output: storage_partition_id: %s, persist_storage: %d\n",
52 storage_partition_id->c_str(), *persist_storage);
53 }
54
55 } // namespace
56
57
26 // A WebContents does not immediately have a RenderProcessHost. It acquires one 58 // A WebContents does not immediately have a RenderProcessHost. It acquires one
27 // on initial navigation. This observer exists until that initial navigation in 59 // on initial navigation. This observer exists until that initial navigation in
28 // order to grab the ID if tis RenderProcessHost so that it can register it as 60 // order to grab the ID if tis RenderProcessHost so that it can register it as
29 // a guest. 61 // a guest.
30 class GuestWebContentsObserver 62 class GuestWebContentsObserver
31 : public content::WebContentsObserver { 63 : public content::WebContentsObserver {
32 public: 64 public:
33 explicit GuestWebContentsObserver(WebContents* guest_web_contents) 65 explicit GuestWebContentsObserver(WebContents* guest_web_contents)
34 : WebContentsObserver(guest_web_contents) { 66 : WebContentsObserver(guest_web_contents) {
35 } 67 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 return GetGuestByInstanceID(guest_instance_id, embedder_render_process_id); 120 return GetGuestByInstanceID(guest_instance_id, embedder_render_process_id);
89 } 121 }
90 122
91 int GuestViewManager::GetNextInstanceID() { 123 int GuestViewManager::GetNextInstanceID() {
92 return ++current_instance_id_; 124 return ++current_instance_id_;
93 } 125 }
94 126
95 content::WebContents* GuestViewManager::CreateGuest( 127 content::WebContents* GuestViewManager::CreateGuest(
96 content::SiteInstance* embedder_site_instance, 128 content::SiteInstance* embedder_site_instance,
97 int instance_id, 129 int instance_id,
98 const std::string& storage_partition_id,
99 bool persist_storage,
100 scoped_ptr<base::DictionaryValue> extra_params) { 130 scoped_ptr<base::DictionaryValue> extra_params) {
131 std::string storage_partition_id;
132 bool persist_storage = false;
133 std::string storage_partition_string;
134 if (extra_params->GetString(guestview::kStoragePartitionId,
135 &storage_partition_string)) {
136 ParsePartitionParam(
137 storage_partition_string, &storage_partition_id, &persist_storage);
138 } else {
139 printf("Not found storagePartitionId key\n");
140 }
141
101 content::RenderProcessHost* embedder_process_host = 142 content::RenderProcessHost* embedder_process_host =
102 embedder_site_instance->GetProcess(); 143 embedder_site_instance->GetProcess();
103 // Validate that the partition id coming from the renderer is valid UTF-8, 144 // Validate that the partition id coming from the renderer is valid UTF-8,
104 // since we depend on this in other parts of the code, such as FilePath 145 // since we depend on this in other parts of the code, such as FilePath
105 // creation. If the validation fails, treat it as a bad message and kill the 146 // creation. If the validation fails, treat it as a bad message and kill the
106 // renderer process. 147 // renderer process.
107 if (!base::IsStringUTF8(storage_partition_id)) { 148 if (!base::IsStringUTF8(storage_partition_id)) {
108 content::RecordAction( 149 content::RecordAction(
109 base::UserMetricsAction("BadMessageTerminate_BPGM")); 150 base::UserMetricsAction("BadMessageTerminate_BPGM"));
110 base::KillProcess( 151 base::KillProcess(
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return false; 343 return false;
303 344
304 return embedder_render_process_id == 345 return embedder_render_process_id ==
305 guest->GetOpener()->embedder_web_contents()->GetRenderProcessHost()-> 346 guest->GetOpener()->embedder_web_contents()->GetRenderProcessHost()->
306 GetID(); 347 GetID();
307 } 348 }
308 349
309 return embedder_render_process_id == 350 return embedder_render_process_id ==
310 guest->embedder_web_contents()->GetRenderProcessHost()->GetID(); 351 guest->embedder_web_contents()->GetRenderProcessHost()->GetID();
311 } 352 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698