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

Side by Side Diff: chrome/renderer/content_settings_observer.cc

Issue 1835753002: Reset content settings caches during provisional load start instead of commit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move things under DidCreateNewDocument instead of DidStartProvisionalLoad Created 4 years, 8 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) 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/renderer/content_settings_observer.h" 5 #include "chrome/renderer/content_settings_observer.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "components/content_settings/content/common/content_settings_messages.h " 9 #include "components/content_settings/content/common/content_settings_messages.h "
10 #include "content/public/common/url_constants.h" 10 #include "content/public/common/url_constants.h"
11 #include "content/public/renderer/document_state.h"
12 #include "content/public/renderer/render_frame.h" 11 #include "content/public/renderer/render_frame.h"
13 #include "content/public/renderer/render_view.h" 12 #include "content/public/renderer/render_view.h"
14 #include "third_party/WebKit/public/platform/URLConversion.h" 13 #include "third_party/WebKit/public/platform/URLConversion.h"
15 #include "third_party/WebKit/public/platform/WebContentSettingCallbacks.h" 14 #include "third_party/WebKit/public/platform/WebContentSettingCallbacks.h"
16 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 15 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
17 #include "third_party/WebKit/public/platform/WebURL.h" 16 #include "third_party/WebKit/public/platform/WebURL.h"
18 #include "third_party/WebKit/public/web/WebDataSource.h" 17 #include "third_party/WebKit/public/web/WebDataSource.h"
19 #include "third_party/WebKit/public/web/WebDocument.h" 18 #include "third_party/WebKit/public/web/WebDocument.h"
20 #include "third_party/WebKit/public/web/WebFrameClient.h" 19 #include "third_party/WebKit/public/web/WebFrameClient.h"
21 #include "third_party/WebKit/public/web/WebLocalFrame.h" 20 #include "third_party/WebKit/public/web/WebLocalFrame.h"
(...skipping 10 matching lines...) Expand all
32 #endif 31 #endif
33 32
34 using blink::WebContentSettingCallbacks; 33 using blink::WebContentSettingCallbacks;
35 using blink::WebDataSource; 34 using blink::WebDataSource;
36 using blink::WebDocument; 35 using blink::WebDocument;
37 using blink::WebFrame; 36 using blink::WebFrame;
38 using blink::WebSecurityOrigin; 37 using blink::WebSecurityOrigin;
39 using blink::WebString; 38 using blink::WebString;
40 using blink::WebURL; 39 using blink::WebURL;
41 using blink::WebView; 40 using blink::WebView;
42 using content::DocumentState;
43 using content::NavigationState;
44 41
45 namespace { 42 namespace {
46 43
47 // This enum is histogrammed, so do not add, reorder, or remove values. 44 // This enum is histogrammed, so do not add, reorder, or remove values.
48 enum { 45 enum {
49 INSECURE_CONTENT_DISPLAY = 0, 46 INSECURE_CONTENT_DISPLAY = 0,
50 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE, // deprecated 47 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE, // deprecated
51 INSECURE_CONTENT_DISPLAY_HOST_WWW_GOOGLE, // deprecated 48 INSECURE_CONTENT_DISPLAY_HOST_WWW_GOOGLE, // deprecated
52 INSECURE_CONTENT_DISPLAY_HTML, 49 INSECURE_CONTENT_DISPLAY_HTML,
53 INSECURE_CONTENT_RUN, 50 INSECURE_CONTENT_RUN,
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 217
221 // Don't swallow LoadBlockedPlugins messages, as they're sent to every 218 // Don't swallow LoadBlockedPlugins messages, as they're sent to every
222 // blocked plugin. 219 // blocked plugin.
223 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message) 220 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver, message)
224 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) 221 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
225 IPC_END_MESSAGE_MAP() 222 IPC_END_MESSAGE_MAP()
226 223
227 return false; 224 return false;
228 } 225 }
229 226
227 void ContentSettingsObserver::DidCreateNewDocument() {
jochen (gone - plz use gerrit) 2016/03/31 15:26:19 didCreateNewDocument is also invoked when somebody
meacer 2016/04/01 19:06:56 Did you mean DidCreateDocumentElement? That's the
228 // Clear "block" flags for the new page. This needs to happen before any of
229 // |allowScript()|, |allowScriptFromSource()|, |allowImage()|, or
230 // |allowPlugins()| is called for the new page so that these functions can
231 // correctly detect that a piece of content flipped from "not blocked" to
232 // "blocked".
233 // This also needs to happen before the document load begins, as parsing the
234 // document can trigger calls to ScriptController::canExecuteScripts.
235 // There is no need to check for same page navigations here as those don't
236 // trigger DidStartProvisionalLoad.
237 ClearBlockedContentSettings();
238 temporarily_allowed_plugins_.clear();
239 }
240
230 void ContentSettingsObserver::DidCommitProvisionalLoad( 241 void ContentSettingsObserver::DidCommitProvisionalLoad(
231 bool is_new_navigation, 242 bool is_new_navigation,
232 bool is_same_page_navigation) { 243 bool is_same_page_navigation) {
233 WebFrame* frame = render_frame()->GetWebFrame(); 244 WebFrame* frame = render_frame()->GetWebFrame();
234 if (frame->parent()) 245 if (frame->parent())
235 return; // Not a top-level navigation. 246 return; // Not a top-level navigation.
236
237 if (!is_same_page_navigation) {
238 // Clear "block" flags for the new page. This needs to happen before any of
239 // |allowScript()|, |allowScriptFromSource()|, |allowImage()|, or
240 // |allowPlugins()| is called for the new page so that these functions can
241 // correctly detect that a piece of content flipped from "not blocked" to
242 // "blocked".
243 ClearBlockedContentSettings();
244 temporarily_allowed_plugins_.clear();
245 }
246
247 GURL url = frame->document().url(); 247 GURL url = frame->document().url();
248 // If we start failing this DCHECK, please makes sure we don't regress 248 // If we start failing this DCHECK, please makes sure we don't regress
249 // this bug: http://code.google.com/p/chromium/issues/detail?id=79304 249 // this bug: http://code.google.com/p/chromium/issues/detail?id=79304
250 DCHECK(frame->document().getSecurityOrigin().toString() == "null" || 250 DCHECK(frame->document().getSecurityOrigin().toString() == "null" ||
251 !url.SchemeIs(url::kDataScheme)); 251 !url.SchemeIs(url::kDataScheme));
252 } 252 }
253 253
254 bool ContentSettingsObserver::allowDatabase(const WebString& name, 254 bool ContentSettingsObserver::allowDatabase(const WebString& name,
255 const WebString& display_name, 255 const WebString& display_name,
256 unsigned long estimated_size) { 256 unsigned long estimated_size) {
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 627
628 // If the scheme is file:, an empty file name indicates a directory listing, 628 // If the scheme is file:, an empty file name indicates a directory listing,
629 // which requires JavaScript to function properly. 629 // which requires JavaScript to function properly.
630 if (base::EqualsASCII(protocol, url::kFileScheme)) { 630 if (base::EqualsASCII(protocol, url::kFileScheme)) {
631 return document_url.SchemeIs(url::kFileScheme) && 631 return document_url.SchemeIs(url::kFileScheme) &&
632 document_url.ExtractFileName().empty(); 632 document_url.ExtractFileName().empty();
633 } 633 }
634 634
635 return false; 635 return false;
636 } 636 }
OLDNEW
« no previous file with comments | « chrome/renderer/content_settings_observer.h ('k') | chrome/renderer/content_settings_observer_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698