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

Side by Side Diff: content/browser/service_worker/service_worker_version.cc

Issue 1335303004: ServiceWorker: Fix the bug in navigate() if windowclient is nested frame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/browser/service_worker/service_worker_version.h" 5 #include "content/browser/service_worker/service_worker_version.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/guid.h" 12 #include "base/guid.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "content/browser/bad_message.h" 22 #include "content/browser/bad_message.h"
23 #include "content/browser/child_process_security_policy_impl.h" 23 #include "content/browser/child_process_security_policy_impl.h"
24 #include "content/browser/frame_host/render_frame_host_impl.h"
24 #include "content/browser/message_port_message_filter.h" 25 #include "content/browser/message_port_message_filter.h"
25 #include "content/browser/message_port_service.h" 26 #include "content/browser/message_port_service.h"
26 #include "content/browser/service_worker/embedded_worker_instance.h" 27 #include "content/browser/service_worker/embedded_worker_instance.h"
27 #include "content/browser/service_worker/embedded_worker_registry.h" 28 #include "content/browser/service_worker/embedded_worker_registry.h"
28 #include "content/browser/service_worker/service_worker_context_core.h" 29 #include "content/browser/service_worker/service_worker_context_core.h"
29 #include "content/browser/service_worker/service_worker_context_wrapper.h" 30 #include "content/browser/service_worker/service_worker_context_wrapper.h"
30 #include "content/browser/service_worker/service_worker_metrics.h" 31 #include "content/browser/service_worker/service_worker_metrics.h"
31 #include "content/browser/service_worker/service_worker_registration.h" 32 #include "content/browser/service_worker/service_worker_registration.h"
32 #include "content/browser/storage_partition_impl.h" 33 #include "content/browser/storage_partition_impl.h"
33 #include "content/common/service_worker/service_worker_messages.h" 34 #include "content/common/service_worker/service_worker_messages.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 using OpenURLCallback = base::Callback<void(int, int)>; 181 using OpenURLCallback = base::Callback<void(int, int)>;
181 182
182 // The OpenURLObserver class is a WebContentsObserver that will wait for a 183 // The OpenURLObserver class is a WebContentsObserver that will wait for a
183 // WebContents to be initialized, run the |callback| passed to its constructor 184 // WebContents to be initialized, run the |callback| passed to its constructor
184 // then self destroy. 185 // then self destroy.
185 // The callback will receive the process and frame ids. If something went wrong 186 // The callback will receive the process and frame ids. If something went wrong
186 // those will be (kInvalidUniqueID, MSG_ROUTING_NONE). 187 // those will be (kInvalidUniqueID, MSG_ROUTING_NONE).
187 // The callback will be called in the IO thread. 188 // The callback will be called in the IO thread.
188 class OpenURLObserver : public WebContentsObserver { 189 class OpenURLObserver : public WebContentsObserver {
189 public: 190 public:
190 OpenURLObserver(WebContents* web_contents, const OpenURLCallback& callback) 191 OpenURLObserver(WebContents* web_contents,
191 : WebContentsObserver(web_contents), callback_(callback) {} 192 RenderFrameHost* render_frame_host,
193 const OpenURLCallback& callback)
194 : WebContentsObserver(web_contents),
195 render_frame_host_(render_frame_host),
196 callback_(callback) {}
192 197
193 void DidCommitProvisionalLoadForFrame( 198 void DidCommitProvisionalLoadForFrame(
194 RenderFrameHost* render_frame_host, 199 RenderFrameHost* render_frame_host,
195 const GURL& validated_url, 200 const GURL& validated_url,
196 ui::PageTransition transition_type) override { 201 ui::PageTransition transition_type) override {
197 DCHECK(web_contents()); 202 DCHECK(web_contents());
198 203
199 if (render_frame_host != web_contents()->GetMainFrame()) 204 if (render_frame_host != render_frame_host_)
200 return; 205 return;
201 206
202 RunCallback(render_frame_host->GetProcess()->GetID(), 207 RunCallback(render_frame_host->GetProcess()->GetID(),
203 render_frame_host->GetRoutingID()); 208 render_frame_host->GetRoutingID());
204 } 209 }
205 210
206 void RenderProcessGone(base::TerminationStatus status) override { 211 void RenderProcessGone(base::TerminationStatus status) override {
207 RunCallback(ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE); 212 RunCallback(ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE);
208 } 213 }
209 214
210 void WebContentsDestroyed() override { 215 void WebContentsDestroyed() override {
211 RunCallback(ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE); 216 RunCallback(ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE);
212 } 217 }
213 218
214 private: 219 private:
215 void RunCallback(int render_process_id, int render_frame_id) { 220 void RunCallback(int render_process_id, int render_frame_id) {
216 // After running the callback, |this| will stop observing, thus 221 // After running the callback, |this| will stop observing, thus
217 // web_contents() should return nullptr and |RunCallback| should no longer 222 // web_contents() should return nullptr and |RunCallback| should no longer
218 // be called. Then, |this| will self destroy. 223 // be called. Then, |this| will self destroy.
219 DCHECK(web_contents()); 224 DCHECK(web_contents());
220 225
221 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 226 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
222 base::Bind(callback_, 227 base::Bind(callback_,
223 render_process_id, 228 render_process_id,
224 render_frame_id)); 229 render_frame_id));
225 Observe(nullptr); 230 Observe(nullptr);
226 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); 231 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
227 } 232 }
228 233
234 RenderFrameHost* render_frame_host_;
229 const OpenURLCallback callback_; 235 const OpenURLCallback callback_;
230 236
231 DISALLOW_COPY_AND_ASSIGN(OpenURLObserver); 237 DISALLOW_COPY_AND_ASSIGN(OpenURLObserver);
232 }; 238 };
233 239
234 void DidOpenURL(const OpenURLCallback& callback, WebContents* web_contents) { 240 void DidOpenURL(const OpenURLCallback& callback, WebContents* web_contents) {
235 DCHECK(web_contents); 241 DCHECK(web_contents);
236 242
237 new OpenURLObserver(web_contents, callback); 243 new OpenURLObserver(web_contents, web_contents->GetMainFrame(), callback);
238 } 244 }
239 245
240 void NavigateClientOnUI(const GURL& url, 246 void NavigateClientOnUI(const GURL& url,
241 const GURL& script_url, 247 const GURL& script_url,
242 int process_id, 248 int process_id,
243 int frame_id, 249 int frame_id,
244 const OpenURLCallback& callback) { 250 const OpenURLCallback& callback) {
245 DCHECK_CURRENTLY_ON(BrowserThread::UI); 251 DCHECK_CURRENTLY_ON(BrowserThread::UI);
246 252
247 RenderFrameHost* render_frame_host = 253 RenderFrameHostImpl* render_frame_host =
248 RenderFrameHost::FromID(process_id, frame_id); 254 RenderFrameHostImpl::FromID(process_id, frame_id);
249 WebContents* web_contents = 255 WebContents* web_contents =
250 WebContents::FromRenderFrameHost(render_frame_host); 256 WebContents::FromRenderFrameHost(render_frame_host);
251 257
252 if (!render_frame_host || !web_contents) { 258 if (!render_frame_host || !web_contents) {
253 BrowserThread::PostTask( 259 BrowserThread::PostTask(
254 BrowserThread::IO, FROM_HERE, 260 BrowserThread::IO, FROM_HERE,
255 base::Bind(callback, ChildProcessHost::kInvalidUniqueID, 261 base::Bind(callback, ChildProcessHost::kInvalidUniqueID,
256 MSG_ROUTING_NONE)); 262 MSG_ROUTING_NONE));
257 return; 263 return;
258 } 264 }
259 265
260 OpenURLParams params( 266 CommonNavigationParams common_params;
261 url, Referrer::SanitizeForRequest( 267 common_params.url = url;
262 url, Referrer(script_url, blink::WebReferrerPolicyDefault)), 268 common_params.referrer = Referrer::SanitizeForRequest(
263 CURRENT_TAB, ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 269 url, Referrer(script_url, blink::WebReferrerPolicyDefault)),
264 true /* is_renderer_initiated */); 270 common_params.transition = ui::PAGE_TRANSITION_AUTO_TOPLEVEL;
nhiroki 2015/09/16 08:00:18 For iframes, the trantition type could be PAGE_TRA
zino 2015/09/17 01:27:45 Done.
265 web_contents->OpenURL(params); 271 render_frame_host->Navigate(common_params, StartNavigationParams(),
Charlie Reis 2015/09/16 18:58:46 It's generally not ok to directly call RenderFrame
zino 2015/09/17 01:27:45 Done.
266 DidOpenURL(callback, web_contents); 272 RequestNavigationParams());
273
274 new OpenURLObserver(web_contents, render_frame_host, callback);
267 } 275 }
268 276
269 void OpenWindowOnUI( 277 void OpenWindowOnUI(
270 const GURL& url, 278 const GURL& url,
271 const GURL& script_url, 279 const GURL& script_url,
272 int process_id, 280 int process_id,
273 const scoped_refptr<ServiceWorkerContextWrapper>& context_wrapper, 281 const scoped_refptr<ServiceWorkerContextWrapper>& context_wrapper,
274 const OpenURLCallback& callback) { 282 const OpenURLCallback& callback) {
275 DCHECK_CURRENTLY_ON(BrowserThread::UI); 283 DCHECK_CURRENTLY_ON(BrowserThread::UI);
276 284
(...skipping 2077 matching lines...) Expand 10 before | Expand all | Expand 10 after
2354 void ServiceWorkerVersion::OnBeginEvent() { 2362 void ServiceWorkerVersion::OnBeginEvent() {
2355 if (should_exclude_from_uma_ || running_status() != RUNNING || 2363 if (should_exclude_from_uma_ || running_status() != RUNNING ||
2356 idle_time_.is_null()) { 2364 idle_time_.is_null()) {
2357 return; 2365 return;
2358 } 2366 }
2359 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - 2367 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() -
2360 idle_time_); 2368 idle_time_);
2361 } 2369 }
2362 2370
2363 } // namespace content 2371 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698