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

Side by Side Diff: chrome/browser/cocoa/notifications/balloon_view_host_mac.mm

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
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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/cocoa/notifications/balloon_view_host_mac.h" 5 #include "chrome/browser/cocoa/notifications/balloon_view_host_mac.h"
6 6
7 #include "base/string_util.h"
8 #include "chrome/browser/browser_list.h"
9 #include "chrome/browser/in_process_webkit/dom_storage_context.h"
10 #include "chrome/browser/in_process_webkit/webkit_context.h"
11 #include "chrome/browser/notifications/balloon.h" 7 #include "chrome/browser/notifications/balloon.h"
12 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/profile.h"
14 #include "chrome/browser/renderer_host/render_view_host.h" 8 #include "chrome/browser/renderer_host/render_view_host.h"
15 #include "chrome/browser/renderer_host/render_widget_host_view.h" 9 #include "chrome/browser/renderer_host/render_widget_host_view.h"
16 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" 10 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
17 #include "chrome/browser/renderer_host/site_instance.h"
18 #include "chrome/browser/renderer_preferences_util.h"
19 #include "chrome/common/notification_service.h"
20 #include "chrome/common/notification_type.h"
21 #include "chrome/common/render_messages.h"
22 #include "chrome/common/renderer_preferences.h"
23 11
24 BalloonViewHost::BalloonViewHost(Balloon* balloon) 12 BalloonViewHost::BalloonViewHost(Balloon* balloon)
25 : initialized_(false), 13 : BalloonHost(balloon) {
26 balloon_(balloon),
27 site_instance_(SiteInstance::CreateSiteInstance(balloon->profile())),
28 render_view_host_(NULL),
29 should_notify_on_disconnect_(false),
30 render_widget_host_view_(NULL) {
31 DCHECK(balloon_);
32 }
33
34 void BalloonViewHost::Shutdown() {
35 if (render_view_host_) {
36 render_view_host_->Shutdown();
37 render_view_host_ = NULL;
38 }
39 }
40
41 WebPreferences BalloonViewHost::GetWebkitPrefs() {
42 WebPreferences prefs;
43 prefs.allow_scripts_to_close_windows = true;
44 return prefs;
45 }
46
47 RendererPreferences BalloonViewHost::GetRendererPrefs(Profile* profile) const {
48 RendererPreferences prefs;
49 renderer_preferences_util::UpdateFromSystemSettings(&prefs, profile);
50 return prefs;
51 }
52
53 void BalloonViewHost::Close(RenderViewHost* render_view_host) {
54 balloon_->CloseByScript();
55 }
56
57 void BalloonViewHost::RenderViewCreated(RenderViewHost* render_view_host) {
58 render_view_host->Send(new ViewMsg_EnablePreferredSizeChangedMode(
59 render_view_host->routing_id()));
60 }
61
62 void BalloonViewHost::RendererReady(RenderViewHost* render_view_host) {
63 should_notify_on_disconnect_ = true;
64 NotificationService::current()->Notify(
65 NotificationType::NOTIFY_BALLOON_CONNECTED,
66 Source<Balloon>(balloon_), NotificationService::NoDetails());
67 }
68
69 void BalloonViewHost::RendererGone(RenderViewHost* render_view_host) {
70 if (!should_notify_on_disconnect_)
71 return;
72
73 should_notify_on_disconnect_ = false;
74 NotificationService::current()->Notify(
75 NotificationType::NOTIFY_BALLOON_DISCONNECTED,
76 Source<Balloon>(balloon_), NotificationService::NoDetails());
77 }
78
79 // RenderViewHostDelegate::View methods implemented to allow links to
80 // open pages in new tabs.
81 void BalloonViewHost::CreateNewWindow(int route_id) {
82 delegate_view_helper_.CreateNewWindow(
83 route_id, balloon_->profile(), site_instance_.get(),
84 DOMUIFactory::GetDOMUIType(balloon_->notification().content_url()), NULL);
85 }
86
87 void BalloonViewHost::ShowCreatedWindow(int route_id,
88 WindowOpenDisposition disposition,
89 const gfx::Rect& initial_pos,
90 bool user_gesture) {
91 // Don't allow pop-ups from notifications.
92 if (disposition == NEW_POPUP)
93 return;
94
95 TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
96 if (contents) {
97 Browser* browser = BrowserList::GetLastActive();
98 browser->AddTabContents(contents, disposition, initial_pos, user_gesture);
99 }
100 }
101
102 void BalloonViewHost::UpdatePreferredSize(const gfx::Size& new_size) {
103 balloon_->SetContentPreferredSize(new_size);
104 } 14 }
105 15
106 void BalloonViewHost::UpdateActualSize(const gfx::Size& new_size) { 16 void BalloonViewHost::UpdateActualSize(const gfx::Size& new_size) {
107 NSView* view = render_widget_host_view_->native_view(); 17 NSView* view = render_widget_host_view_->native_view();
108 NSRect frame = [view frame]; 18 NSRect frame = [view frame];
109 frame.size.width = new_size.width(); 19 frame.size.width = new_size.width();
110 frame.size.height = new_size.height(); 20 frame.size.height = new_size.height();
111 21
112 [view setFrame:frame]; 22 [view setFrame:frame];
113 [view setNeedsDisplay:YES]; 23 [view setNeedsDisplay:YES];
114 } 24 }
115 25
116 void BalloonViewHost::Init() { 26 void BalloonViewHost::InitRenderWidgetHostView() {
117 DCHECK(!render_view_host_) << "BalloonViewHost already initialized."; 27 DCHECK(render_view_host_);
28 render_widget_host_view_ = new RenderWidgetHostViewMac(render_view_host_);
29 }
118 30
119 int64 session_storage_namespace_id = balloon_->profile()->GetWebKitContext()->
120 dom_storage_context()->AllocateSessionStorageNamespaceId();
121
122 render_view_host_ = new RenderViewHost(site_instance_.get(),
123 this, MSG_ROUTING_NONE,
124 session_storage_namespace_id);
125
126 render_widget_host_view_ = new RenderWidgetHostViewMac(render_view_host_);
127 render_view_host_->set_view(render_widget_host_view_);
128 render_view_host_->CreateRenderView(GetProfile()->GetRequestContext());
129 render_view_host_->NavigateToURL(balloon_->notification().content_url());
130 initialized_ = true;
131 }
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/notifications/balloon_view_host_mac.h ('k') | chrome/browser/gtk/notifications/balloon_view_host_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698