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

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: Remove more deadness 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
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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(WebFrame* frame, const GURL& new_url) {
391 // If the URL is still empty, this is a window.open navigation. Check the 391 // If the URL is still empty, this is a window.open navigation. Check the
392 // opener's URL. 392 // opener's URL.
393 GURL old_url(frame->url()); 393 GURL old_url(frame->url());
394 if (old_url.is_empty() && frame->opener()) 394 if (old_url.is_empty() && frame->opener())
395 old_url = frame->opener()->url(); 395 old_url = frame->opener()->url();
396 396
397 return !ExtensionRendererInfo::InSameExtent(old_url, new_url) && 397 ExtensionRendererInfo* extensions = RenderThread::current()->extensions();
398 !ExtensionRendererInfo::GetByURL(old_url); 398 return !extensions->InSameExtent(old_url, new_url) &&
399 !extensions->GetByURL(old_url);
399 } 400 }
400 401
401 // Returns the ISO 639_1 language code of the specified |text|, or 'unknown' 402 // Returns the ISO 639_1 language code of the specified |text|, or 'unknown'
402 // if it failed. 403 // if it failed.
403 static std::string DetermineTextLanguage(const string16& text) { 404 static std::string DetermineTextLanguage(const string16& text) {
404 std::string language = chrome::kUnknownLanguageCode; 405 std::string language = chrome::kUnknownLanguageCode;
405 int num_languages = 0; 406 int num_languages = 0;
406 int text_bytes = 0; 407 int text_bytes = 0;
407 bool is_reliable = false; 408 bool is_reliable = false;
408 Language cld_language = 409 Language cld_language =
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 1881
1881 // WebViewDelegate ------------------------------------------------------------ 1882 // WebViewDelegate ------------------------------------------------------------
1882 1883
1883 void RenderView::LoadNavigationErrorPage(WebFrame* frame, 1884 void RenderView::LoadNavigationErrorPage(WebFrame* frame,
1884 const WebURLRequest& failed_request, 1885 const WebURLRequest& failed_request,
1885 const WebURLError& error, 1886 const WebURLError& error,
1886 const std::string& html, 1887 const std::string& html,
1887 bool replace) { 1888 bool replace) {
1888 GURL failed_url = error.unreachableURL; 1889 GURL failed_url = error.unreachableURL;
1889 std::string alt_html; 1890 std::string alt_html;
1890 ExtensionRendererInfo* extension = NULL; 1891 scoped_refptr<const Extension> extension;
Matt Perry 2011/01/24 20:08:34 just use raw ptrs
Aaron Boodman 2011/01/25 00:27:33 Done.
1891 if (html.empty()) { 1892 if (html.empty()) {
1892 // Use a local error page. 1893 // Use a local error page.
1893 int resource_id; 1894 int resource_id;
1894 DictionaryValue error_strings; 1895 DictionaryValue error_strings;
1895 1896
1896 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme)) 1897 if (failed_url.is_valid() && !failed_url.SchemeIs(chrome::kExtensionScheme))
1897 extension = ExtensionRendererInfo::GetByURL(failed_url); 1898 extension = RenderThread::current()->extensions()->GetByURL(failed_url);
1898 if (extension) { 1899 if (extension) {
1899 LocalizedError::GetAppErrorStrings(error, failed_url, extension, 1900 LocalizedError::GetAppErrorStrings(error, failed_url, extension,
1900 &error_strings); 1901 &error_strings);
1901 1902
1902 // TODO(erikkay): Should we use a different template for different 1903 // TODO(erikkay): Should we use a different template for different
1903 // error messages? 1904 // error messages?
1904 resource_id = IDR_ERROR_APP_HTML; 1905 resource_id = IDR_ERROR_APP_HTML;
1905 } else { 1906 } else {
1906 if (error.domain == WebString::fromUTF8(net::kErrorDomain) && 1907 if (error.domain == WebString::fromUTF8(net::kErrorDomain) &&
1907 error.reason == net::ERR_CACHE_MISS && 1908 error.reason == net::ERR_CACHE_MISS &&
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
2618 void RenderView::show(WebNavigationPolicy policy) { 2619 void RenderView::show(WebNavigationPolicy policy) {
2619 DCHECK(!did_show_) << "received extraneous Show call"; 2620 DCHECK(!did_show_) << "received extraneous Show call";
2620 DCHECK(opener_id_ != MSG_ROUTING_NONE); 2621 DCHECK(opener_id_ != MSG_ROUTING_NONE);
2621 2622
2622 if (did_show_) 2623 if (did_show_)
2623 return; 2624 return;
2624 did_show_ = true; 2625 did_show_ = true;
2625 2626
2626 // Extensions and apps always allowed to create unrequested popups. The second 2627 // Extensions and apps always allowed to create unrequested popups. The second
2627 // check is necessary to include content scripts. 2628 // check is necessary to include content scripts.
2628 if (ExtensionRendererInfo::GetByURL(creator_url_) || 2629 if (RenderThread::current()->extensions()->GetByURL(creator_url_) ||
2629 bindings_utils::GetInfoForCurrentContext()) { 2630 bindings_utils::GetInfoForCurrentContext()) {
2630 opened_by_user_gesture_ = true; 2631 opened_by_user_gesture_ = true;
2631 } 2632 }
2632 2633
2633 // Force new windows to a popup if they were not opened with a user gesture. 2634 // Force new windows to a popup if they were not opened with a user gesture.
2634 if (!opened_by_user_gesture_) { 2635 if (!opened_by_user_gesture_) {
2635 // We exempt background tabs for compat with older versions of Chrome. 2636 // We exempt background tabs for compat with older versions of Chrome.
2636 // TODO(darin): This seems bogus. These should have a user gesture, so 2637 // TODO(darin): This seems bogus. These should have a user gesture, so
2637 // we probably don't need this check. 2638 // we probably don't need this check.
2638 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab) 2639 if (policy != WebKit::WebNavigationPolicyNewBackgroundTab)
(...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after
3919 } 3920 }
3920 } 3921 }
3921 3922
3922 // Check for Native Client modules. 3923 // Check for Native Client modules.
3923 if (mime_type == "application/x-nacl-srpc" && 3924 if (mime_type == "application/x-nacl-srpc" &&
3924 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) { 3925 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl)) {
3925 // NaCl is only permitted when we're in an extension/application with the 3926 // NaCl is only permitted when we're in an extension/application with the
3926 // appropriate permission, or when explicitly enabled on the command line. 3927 // appropriate permission, or when explicitly enabled on the command line.
3927 3928
3928 GURL main_frame_url(webview()->mainFrame()->url()); 3929 GURL main_frame_url(webview()->mainFrame()->url());
3929 ExtensionRendererInfo* extension = 3930 scoped_refptr<const Extension> extension =
3930 ExtensionRendererInfo::GetByURL(main_frame_url); 3931 RenderThread::current()->extensions()->GetByURL(main_frame_url);
3931 bool in_ext = extension != NULL; 3932 bool in_ext = extension != NULL;
3932 bool explicit_enable = 3933 bool explicit_enable =
3933 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl); 3934 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInternalNaCl);
3934 3935
3935 if (in_ext) { 3936 if (in_ext) {
3936 // TODO(cbiffle): NaCl is back to experimental for M7. 3937 // TODO(cbiffle): NaCl is back to experimental for M7.
3937 if (ExtensionProcessBindings::HasPermission(extension->id(), 3938 if (ExtensionProcessBindings::HasPermission(extension->id(),
3938 Extension::kExperimentalPermission)) { 3939 Extension::kExperimentalPermission)) {
3939 in_process_plugin = true; 3940 in_process_plugin = true;
3940 use_pepper_host = true; 3941 use_pepper_host = true;
(...skipping 1447 matching lines...) Expand 10 before | Expand all | Expand 10 after
5388 const ViewMsg_ExecuteCode_Params& params) { 5389 const ViewMsg_ExecuteCode_Params& params) {
5389 std::vector<WebFrame*> frame_vector; 5390 std::vector<WebFrame*> frame_vector;
5390 frame_vector.push_back(frame); 5391 frame_vector.push_back(frame);
5391 if (params.all_frames) 5392 if (params.all_frames)
5392 GetAllChildFrames(frame, &frame_vector); 5393 GetAllChildFrames(frame, &frame_vector);
5393 5394
5394 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin(); 5395 for (std::vector<WebFrame*>::iterator frame_it = frame_vector.begin();
5395 frame_it != frame_vector.end(); ++frame_it) { 5396 frame_it != frame_vector.end(); ++frame_it) {
5396 WebFrame* frame = *frame_it; 5397 WebFrame* frame = *frame_it;
5397 if (params.is_javascript) { 5398 if (params.is_javascript) {
5398 ExtensionRendererInfo* extension = 5399 scoped_refptr<const Extension> extension =
5399 ExtensionRendererInfo::GetByID(params.extension_id); 5400 RenderThread::current()->extensions()->GetByID(params.extension_id);
5400 5401
5401 // Since extension info is sent separately from user script info, they can 5402 // Since extension info is sent separately from user script info, they can
5402 // be out of sync. We just ignore this situation. 5403 // be out of sync. We just ignore this situation.
5403 if (!extension) 5404 if (!extension)
5404 continue; 5405 continue;
5405 5406
5406 const std::vector<URLPattern> host_permissions = 5407 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; 5408 continue;
5415 }
5416 5409
5417 std::vector<WebScriptSource> sources; 5410 std::vector<WebScriptSource> sources;
5418 sources.push_back( 5411 sources.push_back(
5419 WebScriptSource(WebString::fromUTF8(params.code))); 5412 WebScriptSource(WebString::fromUTF8(params.code)));
5420 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id); 5413 UserScriptSlave::InsertInitExtensionCode(&sources, params.extension_id);
5421 frame->executeScriptInIsolatedWorld( 5414 frame->executeScriptInIsolatedWorld(
5422 UserScriptSlave::GetIsolatedWorldId(params.extension_id), 5415 UserScriptSlave::GetIsolatedWorldId(params.extension_id),
5423 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS); 5416 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS);
5424 } else { 5417 } else {
5425 frame->insertStyleText(WebString::fromUTF8(params.code), WebString()); 5418 frame->insertStyleText(WebString::fromUTF8(params.code), WebString());
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
5747 if (cmd == kJavaScriptStressTestSetStressRunType) { 5740 if (cmd == kJavaScriptStressTestSetStressRunType) {
5748 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param)); 5741 v8::Testing::SetStressRunType(static_cast<v8::Testing::StressType>(param));
5749 } else if (cmd == kJavaScriptStressTestPrepareStressRun) { 5742 } else if (cmd == kJavaScriptStressTestPrepareStressRun) {
5750 v8::Testing::PrepareStressRun(param); 5743 v8::Testing::PrepareStressRun(param);
5751 } 5744 }
5752 } 5745 }
5753 5746
5754 void RenderView::OnContextMenuClosed() { 5747 void RenderView::OnContextMenuClosed() {
5755 context_menu_node_.reset(); 5748 context_menu_node_.reset();
5756 } 5749 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698