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

Side by Side Diff: chrome/renderer/translate/translate_helper.cc

Issue 14180010: Translate: browser test for Chrome Translate in an isolated world (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for review Created 7 years, 4 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) 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/translate/translate_helper.h" 5 #include "chrome/renderer/translate/translate_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 TranslateCommonMetrics::ReportPageScheme(url.scheme()); 350 TranslateCommonMetrics::ReportPageScheme(url.scheme());
351 351
352 // Set up v8 isolated world with proper content-security-policy and 352 // Set up v8 isolated world with proper content-security-policy and
353 // security-origin. 353 // security-origin.
354 WebFrame* frame = GetMainFrame(); 354 WebFrame* frame = GetMainFrame();
355 if (frame) { 355 if (frame) {
356 frame->setIsolatedWorldContentSecurityPolicy( 356 frame->setIsolatedWorldContentSecurityPolicy(
357 chrome::ISOLATED_WORLD_ID_TRANSLATE, 357 chrome::ISOLATED_WORLD_ID_TRANSLATE,
358 WebString::fromUTF8(kContentSecurityPolicy)); 358 WebString::fromUTF8(kContentSecurityPolicy));
359 359
360 const char* security_origin = kSecurityOrigin;
361 CommandLine* command_line = CommandLine::ForCurrentProcess();
362 if (command_line->HasSwitch(switches::kTranslateSecurityOrigin)) {
363 std::string alternative = command_line->GetSwitchValueASCII(
364 switches::kTranslateSecurityOrigin);
365 security_origin = alternative.c_str();
366 }
360 frame->setIsolatedWorldSecurityOrigin( 367 frame->setIsolatedWorldSecurityOrigin(
361 chrome::ISOLATED_WORLD_ID_TRANSLATE, 368 chrome::ISOLATED_WORLD_ID_TRANSLATE,
362 WebSecurityOrigin::create(GURL(kSecurityOrigin))); 369 WebSecurityOrigin::create(GURL(security_origin)));
363 } 370 }
364 371
365 if (!IsTranslateLibAvailable()) { 372 if (!IsTranslateLibAvailable()) {
366 // Evaluate the script to add the translation related method to the global 373 // Evaluate the script to add the translation related method to the global
367 // context of the page. 374 // context of the page.
368 ExecuteScript(translate_script); 375 ExecuteScript(translate_script);
369 DCHECK(IsTranslateLibAvailable()); 376 DCHECK(IsTranslateLibAvailable());
370 } 377 }
371 378
372 TranslatePageImpl(0); 379 TranslatePageImpl(0);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 499
493 WebFrame* TranslateHelper::GetMainFrame() { 500 WebFrame* TranslateHelper::GetMainFrame() {
494 WebView* web_view = render_view()->GetWebView(); 501 WebView* web_view = render_view()->GetWebView();
495 502
496 // When the tab is going to be closed, the web_view can be NULL. 503 // When the tab is going to be closed, the web_view can be NULL.
497 if (!web_view) 504 if (!web_view)
498 return NULL; 505 return NULL;
499 506
500 return web_view->mainFrame(); 507 return web_view->mainFrame();
501 } 508 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698