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

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

Issue 6242010: Refactor away most of ExtensionRendererInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/render_thread.cc ('k') | chrome/renderer/user_script_slave.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/render_view.h" 5 #include "chrome/renderer/render_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 380
381 return false; 381 return false;
382 } 382 }
383 383
384 // Returns true if the frame is navigating to an URL either into or out of an 384 // Returns true if the frame is navigating to an URL either into or out of an
385 // extension app's extent. 385 // extension app's extent.
386 // TODO(creis): Temporary workaround for crbug.com/65953: Only return true if 386 // TODO(creis): Temporary workaround for crbug.com/65953: Only return true if
387 // we would enter an extension app's extent from a non-app. We avoid swapping 387 // we would enter an extension app's extent from a non-app. We avoid swapping
388 // processes to exit an app for now, since we do not yet restore context (such 388 // processes to exit an app for now, since we do not yet restore context (such
389 // as window.opener) if the window navigates back. 389 // as window.opener) if the window navigates back.
390 static bool CrossesIntoExtensionExtent(WebFrame* frame, const GURL& new_url) { 390 static bool CrossesIntoExtensionExtent(const ExtensionRendererInfo* extensions,
391 WebFrame* frame,
392 const GURL& new_url) {
391 // If the URL is still empty, this is a window.open navigation. Check the 393 // If the URL is still empty, this is a window.open navigation. Check the
392 // opener's URL. 394 // opener's URL.
393 GURL old_url(frame->url()); 395 GURL old_url(frame->url());
394 if (old_url.is_empty() && frame->opener()) 396 if (old_url.is_empty() && frame->opener())
395 old_url = frame->opener()->url(); 397 old_url = frame->opener()->url();
396 398
397 return !ExtensionRendererInfo::InSameExtent(old_url, new_url) && 399 return !extensions->InSameExtent(old_url, new_url) &&
398 !ExtensionRendererInfo::GetByURL(old_url); 400 !extensions->GetByURL(old_url);
399 } 401 }
400 402
401 // Returns the ISO 639_1 language code of the specified |text|, or 'unknown' 403 // Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
402 // if it failed. 404 // if it failed.
403 static std::string DetermineTextLanguage(const string16& text) { 405 static std::string DetermineTextLanguage(const string16& text) {
404 std::string language = chrome::kUnknownLanguageCode; 406 std::string language = chrome::kUnknownLanguageCode;
405 int num_languages = 0; 407 int num_languages = 0;
406 int text_bytes = 0; 408 int text_bytes = 0;
407 bool is_reliable = false; 409 bool is_reliable = false;
408 Language cld_language = 410 Language cld_language =
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 1882
1881 // WebViewDelegate ------------------------------------------------------------ 1883 // WebViewDelegate ------------------------------------------------------------
1882 1884
1883 void RenderView::LoadNavigationErrorPage(WebFrame* frame, 1885 void RenderView::LoadNavigationErrorPage(WebFrame* frame,
1884 const WebURLRequest& failed_request, 1886 const WebURLRequest& failed_request,
1885 const WebURLError& error, 1887 const WebURLError& error,
1886 const std::string& html, 1888 const std::string& html,
1887 bool replace) { 1889 bool replace) {
1888 GURL failed_url = error.unreachableURL; 1890 GURL failed_url = error.unreachableURL;
1889 std::string alt_html; 1891 std::string alt_html;
1890 ExtensionRendererInfo* extension = NULL; 1892 const Extension* extension = NULL;
1891 if (html.empty()) { 1893 if (html.empty()) {
1892 // Use a local error page. 1894 // Use a local error page.
1893 int resource_id; 1895 int resource_id;
1894 DictionaryValue error_strings; 1896 DictionaryValue error_strings;
1895 1897
1896 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) 1898 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme))
1897 extension = ExtensionRendererInfo::GetByURL(failed_url); 1899 extension = render_thread_->GetExtensions()->GetByURL(failed_url);
1898 if (extension) { 1900 if (extension) {
1899 LocalizedError::GetAppErrorStrings(error, failed_url, extension, 1901 LocalizedError::GetAppErrorStrings(error, failed_url, extension,
1900 &error_strings); 1902 &error_strings);
1901 1903
1902 // TODO(erikkay): Should we use a different template for different 1904 // TODO(erikkay): Should we use a different template for different
1903 // error messages? 1905 // error messages?
1904 resource_id = IDR_ERROR_APP_HTML; 1906 resource_id = IDR_ERROR_APP_HTML;
1905 } else { 1907 } else {
1906 if (error.domain == WebString::fromUTF8(net::kErrorDomain) && 1908 if (error.domain == WebString::fromUTF8(net::kErrorDomain) &&
1907 error.reason == net::ERR_CACHE_MISS && 1909 error.reason == net::ERR_CACHE_MISS &&
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
2618 void RenderView::show(WebNavigationPolicy policy) { 2620 void RenderView::show(WebNavigationPolicy policy) {
2619 DCHECK(!did_show_) << "received extraneous Show call"; 2621 DCHECK(!did_show_) << "received extraneous Show call";
2620 DCHECK(opener_id_ != MSG_ROUTING_NONE); 2622 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2621 2623
2622 if (did_show_) 2624 if (did_show_)
2623 return; 2625 return;
2624 did_show_ = true; 2626 did_show_ = true;
2625 2627
2626 // Extensions and apps always allowed to create unrequested popups. The second 2628 // Extensions and apps always allowed to create unrequested popups. The second
2627 // check is necessary to include content scripts. 2629 // check is necessary to include content scripts.
2628 if (ExtensionRendererInfo::GetByURL(creator_url_) || 2630 if (render_thread_->GetExtensions()->GetByURL(creator_url_) ||
2629 bindings_utils::GetInfoForCurrentContext()) { 2631 bindings_utils::GetInfoForCurrentContext()) {
2630 opened_by_user_gesture_ = true; 2632 opened_by_user_gesture_ = true;
2631 } 2633 }
2632 2634
2633 // Force new windows to a popup if they were not opened with a user gesture. 2635 // Force new windows to a popup if they were not opened with a user gesture.
2634 if (!opened_by_user_gesture_) { 2636 if (!opened_by_user_gesture_) {
2635 // We exempt background tabs for compat with older versions of Chrome. 2637 // We exempt background tabs for compat with older versions of Chrome.
2636 // TODO(darin): This seems bogus. These should have a user gesture, so 2638 // TODO(darin): This seems bogus. These should have a user gesture, so
2637 // we probably don't need this check. 2639 // we probably don't need this check.
2638 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) 2640 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
2956 url.SchemeIs(chrome::kViewSourceScheme); 2958 url.SchemeIs(chrome::kViewSourceScheme);
2957 2959
2958 // If the navigation would cross an app extent boundary, we also need 2960 // If the navigation would cross an app extent boundary, we also need
2959 // to defer to the browser to ensure process isolation. 2961 // to defer to the browser to ensure process isolation.
2960 // TODO(erikkay) This is happening inside of a check to is_content_initiated 2962 // TODO(erikkay) This is happening inside of a check to is_content_initiated
2961 // which means that things like the back button won't trigger it. Is that 2963 // which means that things like the back button won't trigger it. Is that
2962 // OK? 2964 // OK?
2963 // TODO(creis): For now, we only swap processes to enter an app and not 2965 // TODO(creis): For now, we only swap processes to enter an app and not
2964 // exit it, since we currently lose context (e.g., window.opener) if the 2966 // exit it, since we currently lose context (e.g., window.opener) if the
2965 // window navigates back. See crbug.com/65953. 2967 // window navigates back. See crbug.com/65953.
2966 if (!should_fork && CrossesIntoExtensionExtent(frame, url)) { 2968 if (!should_fork &&
2969 CrossesIntoExtensionExtent(
2970 render_thread_->GetExtensions(),
2971 frame,
2972 url)) {
2967 // Include the referrer in this case since we're going from a hosted web 2973 // Include the referrer in this case since we're going from a hosted web
2968 // page. (the packaged case is handled previously by the extension 2974 // page. (the packaged case is handled previously by the extension
2969 // navigation test) 2975 // navigation test)
2970 should_fork = true; 2976 should_fork = true;
2971 send_referrer = true; 2977 send_referrer = true;
2972 } 2978 }
2973 2979
2974 if (should_fork) { 2980 if (should_fork) {
2975 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer"))); 2981 GURL referrer(request.httpHeaderField(WebString::fromUTF8("Referer")));
2976 OpenURL(url, send_referrer ? referrer : GURL(), default_policy); 2982 OpenURL(url, send_referrer ? referrer : GURL(), default_policy);
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
3919 } 3925 }
3920 } 3926 }
3921 3927
3922 // Check for Native Client modules. 3928 // Check for Native Client modules.
3923 if (mime_type == "application/x-nacl-srpc" && 3929 if (mime_type == "application/x-nacl-srpc" &&
3924 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) { 3930 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
3925 // NaCl is only permitted when we're in an extension/application with the 3931 // NaCl is only permitted when we're in an extension/application with the
3926 // appropriate permission, or when explicitly enabled on the command line. 3932 // appropriate permission, or when explicitly enabled on the command line.
3927 3933
3928 GURL main_frame_url(webview()->mainFrame()->url()); 3934 GURL main_frame_url(webview()->mainFrame()->url());
3929 ExtensionRendererInfo* extension = 3935 const Extension* extension =
3930 ExtensionRendererInfo::GetByURL(main_frame_url); 3936 render_thread_->GetExtensions()->GetByURL(main_frame_url);
3931 bool in_ext = extension != NULL; 3937 bool in_ext = extension != NULL;
3932 bool explicit_enable = 3938 bool explicit_enable =
3933 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl); 3939 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl);
3934 3940
3935 if (in_ext) { 3941 if (in_ext) {
3936 // TODO(cbiffle): NaCl is back to experimental for M7. 3942 // TODO(cbiffle): NaCl is back to experimental for M7.
3937 if (ExtensionProcessBindings::HasPermission(extension->id(), 3943 if (ExtensionProcessBindings::HasPermission(extension->id(),
3938 Extension::kExperimentalPermission)) { 3944 Extension::kExperimentalPermission)) {
3939 in_process_plugin = true; 3945 in_process_plugin = true;
3940 use_pepper_host = true; 3946 use_pepper_host = true;
(...skipping 1447 matching lines...) Expand 10 before | Expand all | Expand 10 after
5388 const ViewMsg_ExecuteCode_Params& params) { 5394 const ViewMsg_ExecuteCode_Params& params) {
5389 std::vector<WebFrame*> frame_vector; 5395 std::vector<WebFrame*> frame_vector;
5390 frame_vector.push_back(frame); 5396 frame_vector.push_back(frame);
5391 if (params.all_frames) 5397 if (params.all_frames)
5392 GetAllChildFrames(frame, &frame_vector); 5398 GetAllChildFrames(frame, &frame_vector);
5393 5399
5394 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin(); 5400 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5395 frame_it != frame_vector.end(); ++frame_it) { 5401 frame_it != frame_vector.end(); ++frame_it) {
5396 WebFrame* frame = *frame_it; 5402 WebFrame* frame = *frame_it;
5397 if (params.is_javascript) { 5403 if (params.is_javascript) {
5398 ExtensionRendererInfo* extension = 5404 const Extension* extension =
5399 ExtensionRendererInfo::GetByID(params.extension_id); 5405 render_thread_->GetExtensions()->GetByID(params.extension_id);
5400 5406
5401 // Since extension info is sent separately from user script info, they can 5407 // Since extension info is sent separately from user script info, they can
5402 // be out of sync. We just ignore this situation. 5408 // be out of sync. We just ignore this situation.
5403 if (!extension) 5409 if (!extension)
5404 continue; 5410 continue;
5405 5411
5406 const std::vector<URLPattern> host_permissions = 5412 if (!extension->CanExecuteScriptOnPage(frame->url(), NULL, NULL))
5407 extension->host_permissions();
5408 if (!Extension::CanExecuteScriptOnPage(
5409 frame->url(),
5410 extension->allowed_to_execute_script_everywhere(),
5411 &host_permissions,
5412 NULL,
5413 NULL)) {
5414 continue; 5413 continue;
5415 }
5416 5414
5417 std::vector<WebScriptSource> sources; 5415 std::vector<WebScriptSource> sources;
5418 sources.push_back( 5416 sources.push_back(
5419 WebScriptSource(WebString::fromUTF8(params.code))); 5417 WebScriptSource(WebString::fromUTF8(params.code)));
5420 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id); 5418 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
5421 frame->executeScriptInIsolatedWorld( 5419 frame->executeScriptInIsolatedWorld(
5422 UserScriptSlave::GetIsolatedWorldId(params.extension_id), 5420 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
5423 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); 5421 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5424 } else { 5422 } else {
5425 frame->insertStyleText(WebString::fromUTF8(params.code), WebString()); 5423 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
5747 if (cmd == kJavaScriptStressTestSetStressRunType) { 5745 if (cmd == kJavaScriptStressTestSetStressRunType) {
5748 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); 5746 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param));
5749 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { 5747 } else if (cmd == kJavaScriptStressTestPrepareStressRun) {
5750 v8::Testing::PrepareStressRun(param); 5748 v8::Testing::PrepareStressRun(param);
5751 } 5749 }
5752 } 5750 }
5753 5751
5754 void RenderView::OnContextMenuClosed() { 5752 void RenderView::OnContextMenuClosed() {
5755 context_menu_node_.reset(); 5753 context_menu_node_.reset();
5756 } 5754 }
OLDNEW
« no previous file with comments | « chrome/renderer/render_thread.cc ('k') | chrome/renderer/user_script_slave.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698