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
3 // found in the LICENSE file.
5 #include "chrome/renderer/content_settings_observer.h"
7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h"
9 #include "chrome/common/render_messages.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"
13 #include "content/public/renderer/render_view.h"
14 #include "third_party/WebKit/public/platform/WebPermissionCallbacks.h"
15 #include "third_party/WebKit/public/platform/WebURL.h"
16 #include "third_party/WebKit/public/web/WebDataSource.h"
17 #include "third_party/WebKit/public/web/WebDocument.h"
18 #include "third_party/WebKit/public/web/WebFrameClient.h"
19 #include "third_party/WebKit/public/web/WebLocalFrame.h"
20 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
21 #include "third_party/WebKit/public/web/WebView.h"
22 #include "url/url_constants.h"
24 #if defined(ENABLE_EXTENSIONS)
25 #include "chrome/common/extensions/chrome_extension_messages.h"
26 #include "extensions/common/constants.h"
27 #include "extensions/common/extension.h"
28 #include "extensions/common/permissions/api_permission.h"
29 #include "extensions/common/permissions/permissions_data.h"
30 #include "extensions/renderer/dispatcher.h"
33 using blink::WebDataSource
;
34 using blink::WebDocument
;
35 using blink::WebFrame
;
36 using blink::WebPermissionCallbacks
;
37 using blink::WebSecurityOrigin
;
38 using blink::WebString
;
41 using content::DocumentState
;
42 using content::NavigationState
;
47 INSECURE_CONTENT_DISPLAY
= 0,
48 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE
,
49 INSECURE_CONTENT_DISPLAY_HOST_WWW_GOOGLE
,
50 INSECURE_CONTENT_DISPLAY_HTML
,
52 INSECURE_CONTENT_RUN_HOST_GOOGLE
,
53 INSECURE_CONTENT_RUN_HOST_WWW_GOOGLE
,
54 INSECURE_CONTENT_RUN_TARGET_YOUTUBE
,
55 INSECURE_CONTENT_RUN_JS
,
56 INSECURE_CONTENT_RUN_CSS
,
57 INSECURE_CONTENT_RUN_SWF
,
58 INSECURE_CONTENT_DISPLAY_HOST_YOUTUBE
,
59 INSECURE_CONTENT_RUN_HOST_YOUTUBE
,
60 INSECURE_CONTENT_RUN_HOST_GOOGLEUSERCONTENT
,
61 INSECURE_CONTENT_DISPLAY_HOST_MAIL_GOOGLE
,
62 INSECURE_CONTENT_RUN_HOST_MAIL_GOOGLE
,
63 INSECURE_CONTENT_DISPLAY_HOST_PLUS_GOOGLE
,
64 INSECURE_CONTENT_RUN_HOST_PLUS_GOOGLE
,
65 INSECURE_CONTENT_DISPLAY_HOST_DOCS_GOOGLE
,
66 INSECURE_CONTENT_RUN_HOST_DOCS_GOOGLE
,
67 INSECURE_CONTENT_DISPLAY_HOST_SITES_GOOGLE
,
68 INSECURE_CONTENT_RUN_HOST_SITES_GOOGLE
,
69 INSECURE_CONTENT_DISPLAY_HOST_PICASAWEB_GOOGLE
,
70 INSECURE_CONTENT_RUN_HOST_PICASAWEB_GOOGLE
,
71 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_READER
,
72 INSECURE_CONTENT_RUN_HOST_GOOGLE_READER
,
73 INSECURE_CONTENT_DISPLAY_HOST_CODE_GOOGLE
,
74 INSECURE_CONTENT_RUN_HOST_CODE_GOOGLE
,
75 INSECURE_CONTENT_DISPLAY_HOST_GROUPS_GOOGLE
,
76 INSECURE_CONTENT_RUN_HOST_GROUPS_GOOGLE
,
77 INSECURE_CONTENT_DISPLAY_HOST_MAPS_GOOGLE
,
78 INSECURE_CONTENT_RUN_HOST_MAPS_GOOGLE
,
79 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_SUPPORT
,
80 INSECURE_CONTENT_RUN_HOST_GOOGLE_SUPPORT
,
81 INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_INTL
,
82 INSECURE_CONTENT_RUN_HOST_GOOGLE_INTL
,
83 INSECURE_CONTENT_NUM_EVENTS
86 // Constants for UMA statistic collection.
87 static const char kWWWDotGoogleDotCom
[] = "www.google.com";
88 static const char kMailDotGoogleDotCom
[] = "mail.google.com";
89 static const char kPlusDotGoogleDotCom
[] = "plus.google.com";
90 static const char kDocsDotGoogleDotCom
[] = "docs.google.com";
91 static const char kSitesDotGoogleDotCom
[] = "sites.google.com";
92 static const char kPicasawebDotGoogleDotCom
[] = "picasaweb.google.com";
93 static const char kCodeDotGoogleDotCom
[] = "code.google.com";
94 static const char kGroupsDotGoogleDotCom
[] = "groups.google.com";
95 static const char kMapsDotGoogleDotCom
[] = "maps.google.com";
96 static const char kWWWDotYoutubeDotCom
[] = "www.youtube.com";
97 static const char kDotGoogleUserContentDotCom
[] = ".googleusercontent.com";
98 static const char kGoogleReaderPathPrefix
[] = "/reader/";
99 static const char kGoogleSupportPathPrefix
[] = "/support/";
100 static const char kGoogleIntlPathPrefix
[] = "/intl/";
101 static const char kDotJS
[] = ".js";
102 static const char kDotCSS
[] = ".css";
103 static const char kDotSWF
[] = ".swf";
104 static const char kDotHTML
[] = ".html";
106 // Constants for mixed-content blocking.
107 static const char kGoogleDotCom
[] = "google.com";
109 static bool IsHostInDomain(const std::string
& host
, const std::string
& domain
) {
110 return (EndsWith(host
, domain
, false) &&
111 (host
.length() == domain
.length() ||
112 (host
.length() > domain
.length() &&
113 host
[host
.length() - domain
.length() - 1] == '.')));
116 GURL
GetOriginOrURL(const WebFrame
* frame
) {
117 WebString top_origin
= frame
->top()->securityOrigin().toString();
118 // The |top_origin| is unique ("null") e.g., for file:// URLs. Use the
119 // document URL as the primary URL in those cases.
120 // TODO(alexmos): This is broken for --site-per-process, since top() can be a
121 // WebRemoteFrame which does not have a document(), and the WebRemoteFrame's
122 // URL is not replicated.
123 if (top_origin
== "null")
124 return frame
->top()->document().url();
125 return GURL(top_origin
);
128 ContentSetting
GetContentSettingFromRules(
129 const ContentSettingsForOneType
& rules
,
130 const WebFrame
* frame
,
131 const GURL
& secondary_url
) {
132 ContentSettingsForOneType::const_iterator it
;
133 // If there is only one rule, it's the default rule and we don't need to match
135 if (rules
.size() == 1) {
136 DCHECK(rules
[0].primary_pattern
== ContentSettingsPattern::Wildcard());
137 DCHECK(rules
[0].secondary_pattern
== ContentSettingsPattern::Wildcard());
138 return rules
[0].setting
;
140 const GURL
& primary_url
= GetOriginOrURL(frame
);
141 for (it
= rules
.begin(); it
!= rules
.end(); ++it
) {
142 if (it
->primary_pattern
.Matches(primary_url
) &&
143 it
->secondary_pattern
.Matches(secondary_url
)) {
148 return CONTENT_SETTING_DEFAULT
;
153 ContentSettingsObserver::ContentSettingsObserver(
154 content::RenderFrame
* render_frame
,
155 extensions::Dispatcher
* extension_dispatcher
,
156 bool should_whitelist
)
157 : content::RenderFrameObserver(render_frame
),
158 content::RenderFrameObserverTracker
<ContentSettingsObserver
>(
160 #if defined(ENABLE_EXTENSIONS)
161 extension_dispatcher_(extension_dispatcher
),
163 allow_displaying_insecure_content_(false),
164 allow_running_insecure_content_(false),
165 content_setting_rules_(NULL
),
166 is_interstitial_page_(false),
167 npapi_plugins_blocked_(false),
168 current_request_id_(0),
169 should_whitelist_(should_whitelist
) {
170 ClearBlockedContentSettings();
171 render_frame
->GetWebFrame()->setContentSettingsClient(this);
173 if (render_frame
->GetRenderView()->GetMainRenderFrame() != render_frame
) {
174 // Copy all the settings from the main render frame to avoid race conditions
175 // when initializing this data. See http://crbug.com/333308.
176 ContentSettingsObserver
* parent
= ContentSettingsObserver::Get(
177 render_frame
->GetRenderView()->GetMainRenderFrame());
178 allow_displaying_insecure_content_
=
179 parent
->allow_displaying_insecure_content_
;
180 allow_running_insecure_content_
= parent
->allow_running_insecure_content_
;
181 temporarily_allowed_plugins_
= parent
->temporarily_allowed_plugins_
;
182 is_interstitial_page_
= parent
->is_interstitial_page_
;
183 npapi_plugins_blocked_
= parent
->npapi_plugins_blocked_
;
187 ContentSettingsObserver::~ContentSettingsObserver() {
190 void ContentSettingsObserver::SetContentSettingRules(
191 const RendererContentSettingRules
* content_setting_rules
) {
192 content_setting_rules_
= content_setting_rules
;
195 bool ContentSettingsObserver::IsPluginTemporarilyAllowed(
196 const std::string
& identifier
) {
197 // If the empty string is in here, it means all plugins are allowed.
198 // TODO(bauerb): Remove this once we only pass in explicit identifiers.
199 return (temporarily_allowed_plugins_
.find(identifier
) !=
200 temporarily_allowed_plugins_
.end()) ||
201 (temporarily_allowed_plugins_
.find(std::string()) !=
202 temporarily_allowed_plugins_
.end());
205 void ContentSettingsObserver::DidBlockContentType(
206 ContentSettingsType settings_type
) {
207 DidBlockContentType(settings_type
, base::string16());
210 void ContentSettingsObserver::DidBlockContentType(
211 ContentSettingsType settings_type
,
212 const base::string16
& details
) {
213 // Send multiple ContentBlocked messages if details are provided.
214 if (!content_blocked_
[settings_type
] || !details
.empty()) {
215 content_blocked_
[settings_type
] = true;
216 Send(new ChromeViewHostMsg_ContentBlocked(routing_id(), settings_type
,
221 bool ContentSettingsObserver::OnMessageReceived(const IPC::Message
& message
) {
223 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver
, message
)
224 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAsInterstitial
, OnSetAsInterstitial
)
225 IPC_MESSAGE_HANDLER(ChromeViewMsg_NPAPINotSupported
, OnNPAPINotSupported
)
226 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowDisplayingInsecureContent
,
227 OnSetAllowDisplayingInsecureContent
)
228 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetAllowRunningInsecureContent
,
229 OnSetAllowRunningInsecureContent
)
230 IPC_MESSAGE_HANDLER(ChromeViewMsg_ReloadFrame
, OnReloadFrame
);
231 IPC_MESSAGE_HANDLER(ChromeViewMsg_RequestFileSystemAccessAsyncResponse
,
232 OnRequestFileSystemAccessAsyncResponse
)
233 IPC_MESSAGE_UNHANDLED(handled
= false)
234 IPC_END_MESSAGE_MAP()
238 // Don't swallow LoadBlockedPlugins messages, as they're sent to every
240 IPC_BEGIN_MESSAGE_MAP(ContentSettingsObserver
, message
)
241 IPC_MESSAGE_HANDLER(ChromeViewMsg_LoadBlockedPlugins
, OnLoadBlockedPlugins
)
242 IPC_END_MESSAGE_MAP()
247 void ContentSettingsObserver::DidCommitProvisionalLoad(
248 bool is_new_navigation
,
249 bool is_same_page_navigation
) {
250 WebFrame
* frame
= render_frame()->GetWebFrame();
252 return; // Not a top-level navigation.
254 if (!is_same_page_navigation
) {
255 // Clear "block" flags for the new page. This needs to happen before any of
256 // |allowScript()|, |allowScriptFromSource()|, |allowImage()|, or
257 // |allowPlugins()| is called for the new page so that these functions can
258 // correctly detect that a piece of content flipped from "not blocked" to
260 ClearBlockedContentSettings();
261 temporarily_allowed_plugins_
.clear();
264 GURL url
= frame
->document().url();
265 // If we start failing this DCHECK, please makes sure we don't regress
266 // this bug: http://code.google.com/p/chromium/issues/detail?id=79304
267 DCHECK(frame
->document().securityOrigin().toString() == "null" ||
268 !url
.SchemeIs(url::kDataScheme
));
271 bool ContentSettingsObserver::allowDatabase(const WebString
& name
,
272 const WebString
& display_name
,
273 unsigned long estimated_size
) {
274 WebFrame
* frame
= render_frame()->GetWebFrame();
275 if (frame
->securityOrigin().isUnique() ||
276 frame
->top()->securityOrigin().isUnique())
280 Send(new ChromeViewHostMsg_AllowDatabase(
281 routing_id(), GURL(frame
->securityOrigin().toString()),
282 GURL(frame
->top()->securityOrigin().toString()), name
, display_name
,
287 void ContentSettingsObserver::requestFileSystemAccessAsync(
288 const WebPermissionCallbacks
& callbacks
) {
289 WebFrame
* frame
= render_frame()->GetWebFrame();
290 if (frame
->securityOrigin().isUnique() ||
291 frame
->top()->securityOrigin().isUnique()) {
292 WebPermissionCallbacks
permissionCallbacks(callbacks
);
293 permissionCallbacks
.doDeny();
296 ++current_request_id_
;
297 std::pair
<PermissionRequestMap::iterator
, bool> insert_result
=
298 permission_requests_
.insert(
299 std::make_pair(current_request_id_
, callbacks
));
301 // Verify there are no duplicate insertions.
302 DCHECK(insert_result
.second
);
304 Send(new ChromeViewHostMsg_RequestFileSystemAccessAsync(
305 routing_id(), current_request_id_
,
306 GURL(frame
->securityOrigin().toString()),
307 GURL(frame
->top()->securityOrigin().toString())));
310 bool ContentSettingsObserver::allowImage(bool enabled_per_settings
,
311 const WebURL
& image_url
) {
312 bool allow
= enabled_per_settings
;
313 if (enabled_per_settings
) {
314 if (is_interstitial_page_
)
317 if (IsWhitelistedForContentSettings())
320 if (content_setting_rules_
) {
321 GURL
secondary_url(image_url
);
323 GetContentSettingFromRules(content_setting_rules_
->image_rules
,
324 render_frame()->GetWebFrame(),
325 secondary_url
) != CONTENT_SETTING_BLOCK
;
329 DidBlockContentType(CONTENT_SETTINGS_TYPE_IMAGES
);
333 bool ContentSettingsObserver::allowIndexedDB(const WebString
& name
,
334 const WebSecurityOrigin
& origin
) {
335 WebFrame
* frame
= render_frame()->GetWebFrame();
336 if (frame
->securityOrigin().isUnique() ||
337 frame
->top()->securityOrigin().isUnique())
341 Send(new ChromeViewHostMsg_AllowIndexedDB(
342 routing_id(), GURL(frame
->securityOrigin().toString()),
343 GURL(frame
->top()->securityOrigin().toString()), name
, &result
));
347 bool ContentSettingsObserver::allowPlugins(bool enabled_per_settings
) {
348 return enabled_per_settings
;
351 bool ContentSettingsObserver::allowScript(bool enabled_per_settings
) {
352 if (!enabled_per_settings
)
354 if (is_interstitial_page_
)
357 WebFrame
* frame
= render_frame()->GetWebFrame();
358 std::map
<WebFrame
*, bool>::const_iterator it
=
359 cached_script_permissions_
.find(frame
);
360 if (it
!= cached_script_permissions_
.end())
363 // Evaluate the content setting rules before
364 // |IsWhitelistedForContentSettings|; if there is only the default rule
365 // allowing all scripts, it's quicker this way.
367 if (content_setting_rules_
) {
368 ContentSetting setting
= GetContentSettingFromRules(
369 content_setting_rules_
->script_rules
,
371 GURL(frame
->document().securityOrigin().toString()));
372 allow
= setting
!= CONTENT_SETTING_BLOCK
;
374 allow
= allow
|| IsWhitelistedForContentSettings();
376 cached_script_permissions_
[frame
] = allow
;
380 bool ContentSettingsObserver::allowScriptFromSource(
381 bool enabled_per_settings
,
382 const blink::WebURL
& script_url
) {
383 if (!enabled_per_settings
)
385 if (is_interstitial_page_
)
389 if (content_setting_rules_
) {
390 ContentSetting setting
=
391 GetContentSettingFromRules(content_setting_rules_
->script_rules
,
392 render_frame()->GetWebFrame(),
394 allow
= setting
!= CONTENT_SETTING_BLOCK
;
396 return allow
|| IsWhitelistedForContentSettings();
399 bool ContentSettingsObserver::allowStorage(bool local
) {
400 WebFrame
* frame
= render_frame()->GetWebFrame();
401 if (frame
->securityOrigin().isUnique() ||
402 frame
->top()->securityOrigin().isUnique())
406 StoragePermissionsKey
key(
407 GURL(frame
->document().securityOrigin().toString()), local
);
408 std::map
<StoragePermissionsKey
, bool>::const_iterator permissions
=
409 cached_storage_permissions_
.find(key
);
410 if (permissions
!= cached_storage_permissions_
.end())
411 return permissions
->second
;
413 Send(new ChromeViewHostMsg_AllowDOMStorage(
414 routing_id(), GURL(frame
->securityOrigin().toString()),
415 GURL(frame
->top()->securityOrigin().toString()), local
, &result
));
416 cached_storage_permissions_
[key
] = result
;
420 bool ContentSettingsObserver::allowReadFromClipboard(bool default_value
) {
421 bool allowed
= default_value
;
422 #if defined(ENABLE_EXTENSIONS)
423 extensions::ScriptContext
* calling_context
=
424 extension_dispatcher_
->script_context_set().GetCalling();
425 if (calling_context
) {
426 allowed
|= calling_context
->HasAPIPermission(
427 extensions::APIPermission::kClipboardRead
);
433 bool ContentSettingsObserver::allowWriteToClipboard(bool default_value
) {
434 bool allowed
= default_value
;
435 #if defined(ENABLE_EXTENSIONS)
436 // All blessed extension pages could historically write to the clipboard, so
437 // preserve that for compatibility.
438 extensions::ScriptContext
* calling_context
=
439 extension_dispatcher_
->script_context_set().GetCalling();
440 if (calling_context
) {
441 if (calling_context
->effective_context_type() ==
442 extensions::Feature::BLESSED_EXTENSION_CONTEXT
) {
445 allowed
|= calling_context
->HasAPIPermission(
446 extensions::APIPermission::kClipboardWrite
);
453 bool ContentSettingsObserver::allowMutationEvents(bool default_value
) {
454 return IsPlatformApp() ? false : default_value
;
457 static void SendInsecureContentSignal(int signal
) {
458 UMA_HISTOGRAM_ENUMERATION("SSL.InsecureContent", signal
,
459 INSECURE_CONTENT_NUM_EVENTS
);
462 bool ContentSettingsObserver::allowDisplayingInsecureContent(
463 bool allowed_per_settings
,
464 const blink::WebSecurityOrigin
& origin
,
465 const blink::WebURL
& resource_url
) {
466 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY
);
468 std::string
origin_host(origin
.host().utf8());
469 WebFrame
* frame
= render_frame()->GetWebFrame();
470 GURL
frame_gurl(frame
->document().url());
471 if (IsHostInDomain(origin_host
, kGoogleDotCom
)) {
472 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GOOGLE
);
473 if (StartsWithASCII(frame_gurl
.path(), kGoogleSupportPathPrefix
, false)) {
474 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_SUPPORT
);
475 } else if (StartsWithASCII(frame_gurl
.path(),
476 kGoogleIntlPathPrefix
,
478 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_INTL
);
482 if (origin_host
== kWWWDotGoogleDotCom
) {
483 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_WWW_GOOGLE
);
484 if (StartsWithASCII(frame_gurl
.path(), kGoogleReaderPathPrefix
, false))
485 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GOOGLE_READER
);
486 } else if (origin_host
== kMailDotGoogleDotCom
) {
487 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_MAIL_GOOGLE
);
488 } else if (origin_host
== kPlusDotGoogleDotCom
) {
489 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_PLUS_GOOGLE
);
490 } else if (origin_host
== kDocsDotGoogleDotCom
) {
491 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_DOCS_GOOGLE
);
492 } else if (origin_host
== kSitesDotGoogleDotCom
) {
493 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_SITES_GOOGLE
);
494 } else if (origin_host
== kPicasawebDotGoogleDotCom
) {
495 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_PICASAWEB_GOOGLE
);
496 } else if (origin_host
== kCodeDotGoogleDotCom
) {
497 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_CODE_GOOGLE
);
498 } else if (origin_host
== kGroupsDotGoogleDotCom
) {
499 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_GROUPS_GOOGLE
);
500 } else if (origin_host
== kMapsDotGoogleDotCom
) {
501 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_MAPS_GOOGLE
);
502 } else if (origin_host
== kWWWDotYoutubeDotCom
) {
503 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HOST_YOUTUBE
);
506 GURL
resource_gurl(resource_url
);
507 if (EndsWith(resource_gurl
.path(), kDotHTML
, false))
508 SendInsecureContentSignal(INSECURE_CONTENT_DISPLAY_HTML
);
510 if (allowed_per_settings
|| allow_displaying_insecure_content_
)
513 Send(new ChromeViewHostMsg_DidBlockDisplayingInsecureContent(routing_id()));
518 bool ContentSettingsObserver::allowRunningInsecureContent(
519 bool allowed_per_settings
,
520 const blink::WebSecurityOrigin
& origin
,
521 const blink::WebURL
& resource_url
) {
522 std::string
origin_host(origin
.host().utf8());
523 WebFrame
* frame
= render_frame()->GetWebFrame();
524 GURL
frame_gurl(frame
->document().url());
525 DCHECK_EQ(frame_gurl
.host(), origin_host
);
527 bool is_google
= IsHostInDomain(origin_host
, kGoogleDotCom
);
529 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLE
);
530 if (StartsWithASCII(frame_gurl
.path(), kGoogleSupportPathPrefix
, false)) {
531 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLE_SUPPORT
);
532 } else if (StartsWithASCII(frame_gurl
.path(),
533 kGoogleIntlPathPrefix
,
535 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLE_INTL
);
539 if (origin_host
== kWWWDotGoogleDotCom
) {
540 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_WWW_GOOGLE
);
541 if (StartsWithASCII(frame_gurl
.path(), kGoogleReaderPathPrefix
, false))
542 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLE_READER
);
543 } else if (origin_host
== kMailDotGoogleDotCom
) {
544 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_MAIL_GOOGLE
);
545 } else if (origin_host
== kPlusDotGoogleDotCom
) {
546 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_PLUS_GOOGLE
);
547 } else if (origin_host
== kDocsDotGoogleDotCom
) {
548 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_DOCS_GOOGLE
);
549 } else if (origin_host
== kSitesDotGoogleDotCom
) {
550 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_SITES_GOOGLE
);
551 } else if (origin_host
== kPicasawebDotGoogleDotCom
) {
552 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_PICASAWEB_GOOGLE
);
553 } else if (origin_host
== kCodeDotGoogleDotCom
) {
554 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_CODE_GOOGLE
);
555 } else if (origin_host
== kGroupsDotGoogleDotCom
) {
556 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GROUPS_GOOGLE
);
557 } else if (origin_host
== kMapsDotGoogleDotCom
) {
558 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_MAPS_GOOGLE
);
559 } else if (origin_host
== kWWWDotYoutubeDotCom
) {
560 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_YOUTUBE
);
561 } else if (EndsWith(origin_host
, kDotGoogleUserContentDotCom
, false)) {
562 SendInsecureContentSignal(INSECURE_CONTENT_RUN_HOST_GOOGLEUSERCONTENT
);
565 GURL
resource_gurl(resource_url
);
566 if (resource_gurl
.host() == kWWWDotYoutubeDotCom
)
567 SendInsecureContentSignal(INSECURE_CONTENT_RUN_TARGET_YOUTUBE
);
569 if (EndsWith(resource_gurl
.path(), kDotJS
, false))
570 SendInsecureContentSignal(INSECURE_CONTENT_RUN_JS
);
571 else if (EndsWith(resource_gurl
.path(), kDotCSS
, false))
572 SendInsecureContentSignal(INSECURE_CONTENT_RUN_CSS
);
573 else if (EndsWith(resource_gurl
.path(), kDotSWF
, false))
574 SendInsecureContentSignal(INSECURE_CONTENT_RUN_SWF
);
576 if (!allow_running_insecure_content_
&& !allowed_per_settings
) {
577 DidBlockContentType(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT
, origin
.host());
584 void ContentSettingsObserver::didNotAllowPlugins() {
585 DidBlockContentType(CONTENT_SETTINGS_TYPE_PLUGINS
);
588 void ContentSettingsObserver::didNotAllowScript() {
589 DidBlockContentType(CONTENT_SETTINGS_TYPE_JAVASCRIPT
);
592 bool ContentSettingsObserver::AreNPAPIPluginsBlocked() const {
593 return npapi_plugins_blocked_
;
596 void ContentSettingsObserver::OnLoadBlockedPlugins(
597 const std::string
& identifier
) {
598 temporarily_allowed_plugins_
.insert(identifier
);
601 void ContentSettingsObserver::OnSetAsInterstitial() {
602 is_interstitial_page_
= true;
605 void ContentSettingsObserver::OnNPAPINotSupported() {
606 npapi_plugins_blocked_
= true;
609 void ContentSettingsObserver::OnSetAllowDisplayingInsecureContent(bool allow
) {
610 allow_displaying_insecure_content_
= allow
;
613 void ContentSettingsObserver::OnSetAllowRunningInsecureContent(bool allow
) {
614 allow_running_insecure_content_
= allow
;
615 OnSetAllowDisplayingInsecureContent(allow
);
618 void ContentSettingsObserver::OnReloadFrame() {
619 DCHECK(!render_frame()->GetWebFrame()->parent()) <<
620 "Should only be called on the main frame";
621 render_frame()->GetWebFrame()->reload();
624 void ContentSettingsObserver::OnRequestFileSystemAccessAsyncResponse(
627 PermissionRequestMap::iterator it
= permission_requests_
.find(request_id
);
628 if (it
== permission_requests_
.end())
631 WebPermissionCallbacks callbacks
= it
->second
;
632 permission_requests_
.erase(it
);
641 void ContentSettingsObserver::ClearBlockedContentSettings() {
642 for (size_t i
= 0; i
< arraysize(content_blocked_
); ++i
)
643 content_blocked_
[i
] = false;
644 cached_storage_permissions_
.clear();
645 cached_script_permissions_
.clear();
648 bool ContentSettingsObserver::IsPlatformApp() {
649 #if defined(ENABLE_EXTENSIONS)
650 WebFrame
* frame
= render_frame()->GetWebFrame();
651 WebSecurityOrigin origin
= frame
->document().securityOrigin();
652 const extensions::Extension
* extension
= GetExtension(origin
);
653 return extension
&& extension
->is_platform_app();
659 #if defined(ENABLE_EXTENSIONS)
660 const extensions::Extension
* ContentSettingsObserver::GetExtension(
661 const WebSecurityOrigin
& origin
) const {
662 if (!EqualsASCII(origin
.protocol(), extensions::kExtensionScheme
))
665 const std::string extension_id
= origin
.host().utf8().data();
666 if (!extension_dispatcher_
->IsExtensionActive(extension_id
))
669 return extension_dispatcher_
->extensions()->GetByID(extension_id
);
673 bool ContentSettingsObserver::IsWhitelistedForContentSettings() const {
674 if (should_whitelist_
)
677 // Whitelist ftp directory listings, as they require JavaScript to function
679 if (render_frame()->IsFTPDirectoryListing())
682 WebFrame
* web_frame
= render_frame()->GetWebFrame();
683 return IsWhitelistedForContentSettings(web_frame
->document().securityOrigin(),
684 web_frame
->document().url());
687 bool ContentSettingsObserver::IsWhitelistedForContentSettings(
688 const WebSecurityOrigin
& origin
,
689 const GURL
& document_url
) {
690 if (document_url
== GURL(content::kUnreachableWebDataURL
))
693 if (origin
.isUnique())
694 return false; // Uninitialized document?
696 if (EqualsASCII(origin
.protocol(), content::kChromeUIScheme
))
697 return true; // Browser UI elements should still work.
699 if (EqualsASCII(origin
.protocol(), content::kChromeDevToolsScheme
))
700 return true; // DevTools UI elements should still work.
702 #if defined(ENABLE_EXTENSIONS)
703 if (EqualsASCII(origin
.protocol(), extensions::kExtensionScheme
))
707 // TODO(creis, fsamuel): Remove this once the concept of swapped out
708 // RenderFrames goes away.
709 if (document_url
== GURL(content::kSwappedOutURL
))
712 // If the scheme is file:, an empty file name indicates a directory listing,
713 // which requires JavaScript to function properly.
714 if (EqualsASCII(origin
.protocol(), url::kFileScheme
)) {
715 return document_url
.SchemeIs(url::kFileScheme
) &&
716 document_url
.ExtractFileName().empty();