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

Side by Side Diff: chrome/browser/notifications/balloon_host.cc

Issue 1055005: Refactor BalloonViewHost, removing a lot of duplicate code that crept into no... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 10 years, 9 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
(Empty)
1 // Copyright (c) 2010 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.
4
5 #include "chrome/browser/notifications/balloon_host.h"
6
7 #include "chrome/browser/browser_list.h"
8 #include "chrome/browser/in_process_webkit/webkit_context.h"
9 #include "chrome/browser/extensions/extension_process_manager.h"
10 #include "chrome/browser/notifications/balloon.h"
11 #include "chrome/browser/profile.h"
12 #include "chrome/browser/renderer_host/render_view_host.h"
13 #include "chrome/browser/renderer_host/site_instance.h"
14 #include "chrome/browser/renderer_preferences_util.h"
15 #include "chrome/common/bindings_policy.h"
16 #include "chrome/common/notification_service.h"
17 #include "chrome/common/notification_type.h"
18 #include "chrome/common/render_messages.h"
19 #include "chrome/common/renderer_preferences.h"
20 #include "chrome/common/url_constants.h"
21
22 BalloonHost::BalloonHost(Balloon* balloon)
23 : render_view_host_(NULL),
24 balloon_(balloon),
25 initialized_(false),
26 should_notify_on_disconnect_(false),
27 is_extension_page_(false) {
28 DCHECK(balloon_);
29
30 // If the notification is for an extension URL, make sure to use the extension
31 // process to render it, so that it can communicate with other views in the
32 // extension.
33 const GURL& balloon_url = balloon_->notification().content_url();
34 if (balloon_url.SchemeIs(chrome::kExtensionScheme)) {
35 is_extension_page_ = true;
36 site_instance_ =
37 balloon_->profile()->GetExtensionProcessManager()->GetSiteInstanceForURL(
38 balloon_url);
39 } else {
40 site_instance_ = SiteInstance::CreateSiteInstance(balloon_->profile());
41 }
42 }
43
44 void BalloonHost::Shutdown() {
45 if (render_view_host_) {
46 render_view_host_->Shutdown();
47 render_view_host_ = NULL;
48 }
49 }
50
51 WebPreferences BalloonHost::GetWebkitPrefs() {
52 WebPreferences prefs;
53 prefs.allow_scripts_to_close_windows = true;
54 return prefs;
55 }
56
57 void BalloonHost::Close(RenderViewHost* render_view_host) {
58 balloon_->CloseByScript();
59 }
60
61
62 void BalloonHost::RenderViewCreated(RenderViewHost* render_view_host) {
63 render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode(
64 render_view_host->routing_id()));
65 }
66
67 void BalloonHost::RendererReady(RenderViewHost* render_view_host) {
68 should_notify_on_disconnect_ = true;
69 NotificationService::current()->Notify(
70 NotificationType::NOTIFY_BALLOON_CONNECTED,
71 Source<Balloon>(balloon_), NotificationService::NoDetails());
72 }
73
74 void BalloonHost::RendererGone(RenderViewHost* render_view_host) {
75 if (!should_notify_on_disconnect_)
76 return;
77
78 should_notify_on_disconnect_ = false;
79 NotificationService::current()->Notify(
80 NotificationType::NOTIFY_BALLOON_DISCONNECTED,
81 Source<Balloon>(balloon_), NotificationService::NoDetails());
82 }
83
84 // RenderViewHostDelegate::View methods implemented to allow links to
85 // open pages in new tabs.
86 void BalloonHost::CreateNewWindow(int route_id) {
87 delegate_view_helper_.CreateNewWindow(
88 route_id, balloon_->profile(), site_instance_.get(),
89 DOMUIFactory::GetDOMUIType(balloon_->notification().content_url()), NULL);
90 }
91
92 void BalloonHost::ShowCreatedWindow(int route_id,
93 WindowOpenDisposition disposition,
94 const gfx::Rect& initial_pos,
95 bool user_gesture) {
96 // Don't allow pop-ups from notifications.
97 if (disposition == NEW_POPUP)
98 return;
99
100 TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
101 if (contents) {
102 Browser* browser = BrowserList::GetLastActive();
103 browser->AddTabContents(contents, disposition, initial_pos, user_gesture);
104 }
105 }
106
107 void BalloonHost::UpdatePreferredSize(const gfx::Size& new_size) {
108 balloon_->SetContentPreferredSize(new_size);
109 }
110
111 void BalloonHost::Init() {
112 DCHECK(!render_view_host_) << "BalloonViewHost already initialized.";
113 int64 session_storage_namespace_id = balloon_->profile()->GetWebKitContext()->
114 dom_storage_context()->AllocateSessionStorageNamespaceId();
115 RenderViewHost* rvh = new RenderViewHost(site_instance_.get(),
116 this, MSG_ROUTING_NONE,
117 session_storage_namespace_id);
118 if (is_extension_page_)
119 rvh->AllowBindings(BindingsPolicy::EXTENSION);
120
121 // Do platform-specific initialization.
122 render_view_host_ = rvh;
123 InitRenderWidgetHostView();
124 DCHECK(render_widget_host_view());
125
126 rvh->set_view(render_widget_host_view());
127 rvh->CreateRenderView(GetProfile()->GetRequestContext());
128 rvh->NavigateToURL(balloon_->notification().content_url());
129
130 initialized_ = true;
131 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/balloon_host.h ('k') | chrome/browser/views/notifications/balloon_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698