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

Side by Side Diff: chrome/browser/extensions/extension_host.cc

Issue 7464009: Removal of Profile from content part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: slight tweaking for comments Created 9 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) 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/browser/extensions/extension_host.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 //////////////// 126 ////////////////
127 // ExtensionHost 127 // ExtensionHost
128 128
129 ExtensionHost::ExtensionHost(const Extension* extension, 129 ExtensionHost::ExtensionHost(const Extension* extension,
130 SiteInstance* site_instance, 130 SiteInstance* site_instance,
131 const GURL& url, 131 const GURL& url,
132 ViewType::Type host_type) 132 ViewType::Type host_type)
133 : extension_(extension), 133 : extension_(extension),
134 extension_id_(extension->id()), 134 extension_id_(extension->id()),
135 profile_(site_instance->browsing_instance()->profile()), 135 profile_(Profile::FromBrowserContext(
136 site_instance->browsing_instance()->browser_context())),
136 did_stop_loading_(false), 137 did_stop_loading_(false),
137 document_element_available_(false), 138 document_element_available_(false),
138 url_(url), 139 url_(url),
139 ALLOW_THIS_IN_INITIALIZER_LIST( 140 ALLOW_THIS_IN_INITIALIZER_LIST(
140 extension_function_dispatcher_(profile_, this)), 141 extension_function_dispatcher_(profile_, this)),
141 extension_host_type_(host_type), 142 extension_host_type_(host_type),
142 associated_tab_contents_(NULL) { 143 associated_tab_contents_(NULL) {
143 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE, 144 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE,
144 NULL); 145 NULL);
145 if (enable_dom_automation_) 146 if (enable_dom_automation_)
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 if (extension_host_type_ == ViewType::EXTENSION_POPUP || 483 if (extension_host_type_ == ViewType::EXTENSION_POPUP ||
483 extension_host_type_ == ViewType::EXTENSION_DIALOG || 484 extension_host_type_ == ViewType::EXTENSION_DIALOG ||
484 extension_host_type_ == ViewType::EXTENSION_INFOBAR) { 485 extension_host_type_ == ViewType::EXTENSION_INFOBAR) {
485 NotificationService::current()->Notify( 486 NotificationService::current()->Notify(
486 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 487 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
487 Source<Profile>(profile_), 488 Source<Profile>(profile_),
488 Details<ExtensionHost>(this)); 489 Details<ExtensionHost>(this));
489 } 490 }
490 } 491 }
491 492
492 RendererPreferences ExtensionHost::GetRendererPrefs(Profile* profile) const { 493 RendererPreferences ExtensionHost::GetRendererPrefs(
494 content::BrowserContext* browser_context) const {
495 Profile* profile = Profile::FromBrowserContext(browser_context);
493 RendererPreferences preferences; 496 RendererPreferences preferences;
494 497
495 TabContents* associated_contents = GetAssociatedTabContents(); 498 TabContents* associated_contents = GetAssociatedTabContents();
496 if (associated_contents) 499 if (associated_contents)
497 preferences = 500 preferences =
498 static_cast<RenderViewHostDelegate*>(associated_contents)-> 501 static_cast<RenderViewHostDelegate*>(associated_contents)->
499 GetRendererPrefs(profile); 502 GetRendererPrefs(profile);
500 503
501 renderer_preferences_util::UpdateFromSystemSettings(&preferences, profile); 504 renderer_preferences_util::UpdateFromSystemSettings(&preferences, profile);
502 return preferences; 505 return preferences;
503 } 506 }
504 507
505 WebPreferences ExtensionHost::GetWebkitPrefs() { 508 WebPreferences ExtensionHost::GetWebkitPrefs() {
506 Profile* profile = render_view_host()->process()->profile(); 509 Profile* profile = Profile::FromBrowserContext(
510 render_view_host()->process()->browser_context());
507 WebPreferences webkit_prefs = 511 WebPreferences webkit_prefs =
508 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, 512 RenderViewHostDelegateHelper::GetWebkitPrefs(profile,
509 false); // is_web_ui 513 false); // is_web_ui
510 // Extensions are trusted so we override any user preferences for disabling 514 // Extensions are trusted so we override any user preferences for disabling
511 // javascript or images. 515 // javascript or images.
512 webkit_prefs.loads_images_automatically = true; 516 webkit_prefs.loads_images_automatically = true;
513 webkit_prefs.javascript_enabled = true; 517 webkit_prefs.javascript_enabled = true;
514 518
515 if (extension_host_type_ == ViewType::EXTENSION_POPUP || 519 if (extension_host_type_ == ViewType::EXTENSION_POPUP ||
516 extension_host_type_ == ViewType::EXTENSION_DIALOG || 520 extension_host_type_ == ViewType::EXTENSION_DIALOG ||
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 } 582 }
579 583
580 void ExtensionHost::HandleMouseActivate() { 584 void ExtensionHost::HandleMouseActivate() {
581 } 585 }
582 586
583 void ExtensionHost::CreateNewWindow( 587 void ExtensionHost::CreateNewWindow(
584 int route_id, 588 int route_id,
585 const ViewHostMsg_CreateWindow_Params& params) { 589 const ViewHostMsg_CreateWindow_Params& params) {
586 // TODO(aa): Use the browser's profile if the extension is split mode 590 // TODO(aa): Use the browser's profile if the extension is split mode
587 // incognito. 591 // incognito.
592 Profile* profile = Profile::FromBrowserContext(
593 render_view_host()->process()->browser_context());
588 TabContents* new_contents = delegate_view_helper_.CreateNewWindow( 594 TabContents* new_contents = delegate_view_helper_.CreateNewWindow(
589 route_id, 595 route_id,
590 render_view_host()->process()->profile(), 596 profile,
591 site_instance(), 597 site_instance(),
592 ChromeWebUIFactory::GetInstance()->GetWebUIType( 598 ChromeWebUIFactory::GetInstance()->GetWebUIType(
593 render_view_host()->process()->profile(), url_), 599 render_view_host()->process()->browser_context(), url_),
594 this, 600 this,
595 params.window_container_type, 601 params.window_container_type,
596 params.frame_name); 602 params.frame_name);
597 603
598 TabContents* associated_contents = GetAssociatedTabContents(); 604 TabContents* associated_contents = GetAssociatedTabContents();
599 if (associated_contents && associated_contents->delegate()) 605 if (associated_contents && associated_contents->delegate())
600 associated_contents->delegate()->TabContentsCreated(new_contents); 606 associated_contents->delegate()->TabContentsCreated(new_contents);
601 } 607 }
602 608
603 void ExtensionHost::CreateNewWidget(int route_id, 609 void ExtensionHost::CreateNewWidget(int route_id,
(...skipping 12 matching lines...) Expand all
616 site_instance()->GetProcess()); 622 site_instance()->GetProcess());
617 } 623 }
618 624
619 void ExtensionHost::ShowCreatedWindow(int route_id, 625 void ExtensionHost::ShowCreatedWindow(int route_id,
620 WindowOpenDisposition disposition, 626 WindowOpenDisposition disposition,
621 const gfx::Rect& initial_pos, 627 const gfx::Rect& initial_pos,
622 bool user_gesture) { 628 bool user_gesture) {
623 TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id); 629 TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
624 if (!contents) 630 if (!contents)
625 return; 631 return;
632 Profile* profile = Profile::FromBrowserContext(contents->browser_context());
626 633
627 if (disposition == NEW_POPUP) { 634 if (disposition == NEW_POPUP) {
628 // Find a browser with a matching profile for creating a popup. 635 // Find a browser with a matching profile for creating a popup.
629 // (If none is found, NULL argument to NavigateParams is valid.) 636 // (If none is found, NULL argument to NavigateParams is valid.)
630 Browser* browser = BrowserList::FindTabbedBrowser( 637 Browser* browser = BrowserList::FindTabbedBrowser(
631 contents->profile(), 638 profile, false); // Match incognito exactly.
632 false); // Match incognito exactly.
633 TabContentsWrapper* wrapper = new TabContentsWrapper(contents); 639 TabContentsWrapper* wrapper = new TabContentsWrapper(contents);
634 browser::NavigateParams params(browser, wrapper); 640 browser::NavigateParams params(browser, wrapper);
635 if (!browser) 641 if (!browser)
636 params.profile = contents->profile(); 642 params.profile = profile;
637 // The extension_app_id parameter ends up as app_name in the Browser 643 // The extension_app_id parameter ends up as app_name in the Browser
638 // which causes the Browser to return true for is_app(). This affects 644 // which causes the Browser to return true for is_app(). This affects
639 // among other things, whether the location bar gets displayed. 645 // among other things, whether the location bar gets displayed.
640 params.extension_app_id = extension_id_; 646 params.extension_app_id = extension_id_;
641 params.disposition = NEW_POPUP; 647 params.disposition = NEW_POPUP;
642 params.window_bounds = initial_pos; 648 params.window_bounds = initial_pos;
643 params.window_action = browser::NavigateParams::SHOW_WINDOW; 649 params.window_action = browser::NavigateParams::SHOW_WINDOW;
644 params.user_gesture = user_gesture; 650 params.user_gesture = user_gesture;
645 browser::Navigate(&params); 651 browser::Navigate(&params);
646 return; 652 return;
647 } 653 }
648 654
649 // If the tab contents isn't a popup, it's a normal tab. We need to find a 655 // If the tab contents isn't a popup, it's a normal tab. We need to find a
650 // home for it. This is typically a Browser, but it can also be some other 656 // home for it. This is typically a Browser, but it can also be some other
651 // TabContentsDelegate in the case of ChromeFrame. 657 // TabContentsDelegate in the case of ChromeFrame.
652 658
653 // First, if the creating extension view was associated with a tab contents, 659 // First, if the creating extension view was associated with a tab contents,
654 // use that tab content's delegate. We must be careful here that the 660 // use that tab content's delegate. We must be careful here that the
655 // associated tab contents has the same profile as the new tab contents. In 661 // associated tab contents has the same profile as the new tab contents. In
656 // the case of extensions in 'spanning' incognito mode, they can mismatch. 662 // the case of extensions in 'spanning' incognito mode, they can mismatch.
657 // We don't want to end up putting a normal tab into an incognito window, or 663 // We don't want to end up putting a normal tab into an incognito window, or
658 // vice versa. 664 // vice versa.
659 TabContents* associated_contents = GetAssociatedTabContents(); 665 TabContents* associated_contents = GetAssociatedTabContents();
660 if (associated_contents && 666 if (associated_contents &&
661 associated_contents->profile() == contents->profile()) { 667 associated_contents->browser_context() == contents->browser_context()) {
662 associated_contents->AddNewContents( 668 associated_contents->AddNewContents(
663 contents, disposition, initial_pos, user_gesture); 669 contents, disposition, initial_pos, user_gesture);
664 return; 670 return;
665 } 671 }
666 672
667 // If there's no associated tab contents, or it doesn't have a matching 673 // If there's no associated tab contents, or it doesn't have a matching
668 // profile, try finding an open window. Again, we must make sure to find a 674 // profile, try finding an open window. Again, we must make sure to find a
669 // window with the correct profile. 675 // window with the correct profile.
670 Browser* browser = BrowserList::FindTabbedBrowser( 676 Browser* browser = BrowserList::FindTabbedBrowser(
671 contents->profile(), 677 profile, false); // Match incognito exactly.
672 false); // Match incognito exactly.
673 678
674 // If there's no Browser open with the right profile, create a new one. 679 // If there's no Browser open with the right profile, create a new one.
675 if (!browser) { 680 if (!browser) {
676 browser = Browser::Create(contents->profile()); 681 browser = Browser::Create(profile);
677 browser->window()->Show(); 682 browser->window()->Show();
678 } 683 }
679 browser->AddTabContents(contents, disposition, initial_pos, user_gesture); 684 browser->AddTabContents(contents, disposition, initial_pos, user_gesture);
680 } 685 }
681 686
682 void ExtensionHost::ShowCreatedWidget(int route_id, 687 void ExtensionHost::ShowCreatedWidget(int route_id,
683 const gfx::Rect& initial_pos) { 688 const gfx::Rect& initial_pos) {
684 ShowCreatedWidgetInternal(delegate_view_helper_.GetCreatedWidget(route_id), 689 ShowCreatedWidgetInternal(delegate_view_helper_.GetCreatedWidget(route_id),
685 initial_pos); 690 initial_pos);
686 } 691 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 } 791 }
787 } 792 }
788 793
789 void ExtensionHost::OnRunFileChooser( 794 void ExtensionHost::OnRunFileChooser(
790 const ViewHostMsg_RunFileChooser_Params& params) { 795 const ViewHostMsg_RunFileChooser_Params& params) {
791 if (file_select_helper_.get() == NULL) 796 if (file_select_helper_.get() == NULL)
792 file_select_helper_.reset(new FileSelectHelper(profile())); 797 file_select_helper_.reset(new FileSelectHelper(profile()));
793 file_select_helper_->RunFileChooser(render_view_host_, 798 file_select_helper_->RunFileChooser(render_view_host_,
794 GetAssociatedTabContents(), params); 799 GetAssociatedTabContents(), params);
795 } 800 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.h ('k') | chrome/browser/extensions/extension_web_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698