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

Side by Side Diff: chrome/browser/cocoa/location_bar_view_mac.h

Issue 600133: Mac: Content blocked icons. (Closed)
Patch Set: comments andybons Created 10 years, 10 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
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 #ifndef CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_ 5 #ifndef CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_
6 #define CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_ 6 #define CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_
7 7
8 #include <string> 8 #include <string>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
11 11
12 #import <Cocoa/Cocoa.h> 12 #import <Cocoa/Cocoa.h>
13 13
14 #include "base/scoped_nsobject.h" 14 #include "base/scoped_nsobject.h"
15 #include "base/scoped_ptr.h" 15 #include "base/scoped_ptr.h"
16 #include "base/scoped_vector.h"
16 #include "chrome/browser/autocomplete/autocomplete_edit.h" 17 #include "chrome/browser/autocomplete/autocomplete_edit.h"
17 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" 18 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
18 #include "chrome/browser/extensions/image_loading_tracker.h" 19 #include "chrome/browser/extensions/image_loading_tracker.h"
19 #include "chrome/browser/location_bar.h" 20 #include "chrome/browser/location_bar.h"
20 #include "chrome/browser/toolbar_model.h" 21 #include "chrome/browser/toolbar_model.h"
22 #include "chrome/common/content_settings_types.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 23 #include "third_party/skia/include/core/SkBitmap.h"
22 24
23 @class AutocompleteTextField; 25 @class AutocompleteTextField;
24 class BubblePositioner; 26 class BubblePositioner;
25 class CommandUpdater; 27 class CommandUpdater;
26 @class ExtensionPopupController; 28 @class ExtensionPopupController;
27 class Profile; 29 class Profile;
28 class ToolbarModel; 30 class ToolbarModel;
29 31
30 // A C++ bridge class that represents the location bar UI element to 32 // A C++ bridge class that represents the location bar UI element to
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 void SetLabel(NSString* text, NSFont* baseFont, NSColor* color); 145 void SetLabel(NSString* text, NSFont* baseFont, NSColor* color);
144 146
145 // Sets the visibility. SetImage() should be called with a valid image 147 // Sets the visibility. SetImage() should be called with a valid image
146 // before the visibility is set to |true|. 148 // before the visibility is set to |true|.
147 void SetVisible(bool visible); 149 void SetVisible(bool visible);
148 150
149 const NSImage* GetImage() const { return image_; } 151 const NSImage* GetImage() const { return image_; }
150 const NSAttributedString* GetLabel() const { return label_; } 152 const NSAttributedString* GetLabel() const { return label_; }
151 bool IsVisible() const { return visible_; } 153 bool IsVisible() const { return visible_; }
152 154
155 // Returns the tooltip for this image view or |nil| if there is none.
156 virtual const NSString* GetToolTip() { return nil; }
157
158 // Called on mouse down.
159 virtual void OnMousePressed(NSRect bounds) {}
160
161 // Called to get the icon's context menu. Return |nil| for no menu.
162 virtual NSMenu* GetMenu() { return nil; }
163
153 private: 164 private:
154 scoped_nsobject<NSImage> image_; 165 scoped_nsobject<NSImage> image_;
155 166
156 // The label shown next to the icon, or nil if none. 167 // The label shown next to the icon, or nil if none.
157 scoped_nsobject<NSAttributedString> label_; 168 scoped_nsobject<NSAttributedString> label_;
158 169
159 bool visible_; 170 bool visible_;
160 171
161 DISALLOW_COPY_AND_ASSIGN(LocationBarImageView); 172 DISALLOW_COPY_AND_ASSIGN(LocationBarImageView);
162 }; 173 };
163 174
164 // SecurityImageView is used to display the lock or warning icon when the 175 // SecurityImageView is used to display the lock or warning icon when the
165 // current URL's scheme is https. 176 // current URL's scheme is https.
166 class SecurityImageView : public LocationBarImageView { 177 class SecurityImageView : public LocationBarImageView {
167 public: 178 public:
168 enum Image { 179 enum Image {
169 LOCK = 0, 180 LOCK = 0,
170 WARNING 181 WARNING
171 }; 182 };
172 183
173 SecurityImageView(LocationBarViewMac* owner, 184 SecurityImageView(LocationBarViewMac* owner,
174 Profile* profile, 185 Profile* profile,
175 ToolbarModel* model); 186 ToolbarModel* model);
176 virtual ~SecurityImageView(); 187 virtual ~SecurityImageView();
177 188
178 // Sets the image to the appropriate icon. 189 // Sets the image to the appropriate icon.
179 void SetImageShown(Image image); 190 void SetImageShown(Image image);
180 191
181 // Shows the page info dialog. Virtual so it can be overridden for testing. 192 // Shows the page info dialog.
182 virtual bool OnMousePressed(); 193 virtual void OnMousePressed(NSRect bounds);
183 194
184 private: 195 private:
185 // The lock icon shown when using HTTPS. Loaded lazily, the first time it's 196 // The lock icon shown when using HTTPS. Loaded lazily, the first time it's
186 // needed. 197 // needed.
187 scoped_nsobject<NSImage> lock_icon_; 198 scoped_nsobject<NSImage> lock_icon_;
188 199
189 // The warning icon shown when HTTPS is broken. Loaded lazily, the first 200 // The warning icon shown when HTTPS is broken. Loaded lazily, the first
190 // time it's needed. 201 // time it's needed.
191 scoped_nsobject<NSImage> warning_icon_; 202 scoped_nsobject<NSImage> warning_icon_;
192 203
(...skipping 23 matching lines...) Expand all
216 227
217 void set_preview_enabled(bool enabled) { preview_enabled_ = enabled; } 228 void set_preview_enabled(bool enabled) { preview_enabled_ = enabled; }
218 229
219 bool preview_enabled() { return preview_enabled_; } 230 bool preview_enabled() { return preview_enabled_; }
220 231
221 // Return the size of the image, or a default size if no image available 232 // Return the size of the image, or a default size if no image available
222 // and preview is enabled. 233 // and preview is enabled.
223 virtual NSSize GetImageSize(); 234 virtual NSSize GetImageSize();
224 235
225 // Either notify listeners or show a popup depending on the Page Action. 236 // Either notify listeners or show a popup depending on the Page Action.
226 // Virtual so it can be overridden for testing. 237 virtual void OnMousePressed(NSRect bounds);
227 virtual bool OnMousePressed(NSRect bounds);
228 238
229 // Overridden from ImageLoadingTracker. 239 // Overridden from ImageLoadingTracker.
230 virtual void OnImageLoaded(SkBitmap* image, size_t index); 240 virtual void OnImageLoaded(SkBitmap* image, size_t index);
231 241
232 // Called to notify the Page Action that it should determine whether to be 242 // Called to notify the Page Action that it should determine whether to be
233 // visible or hidden. |contents| is the TabContents that is active, |url| 243 // visible or hidden. |contents| is the TabContents that is active, |url|
234 // is the current page URL. 244 // is the current page URL.
235 void UpdateVisibility(TabContents* contents, const GURL& url); 245 void UpdateVisibility(TabContents* contents, const GURL& url);
236 246
237 // Sets the tooltip for this Page Action image. 247 // Sets the tooltip for this Page Action image.
238 void SetToolTip(NSString* tooltip); 248 void SetToolTip(NSString* tooltip);
239 void SetToolTip(std::string tooltip); 249 void SetToolTip(std::string tooltip);
240 250
241 // Returns the tooltip for this Page Action image or |nil| if there is none. 251 // Returns the tooltip for this Page Action image or |nil| if there is none.
242 const NSString* GetToolTip(); 252 virtual const NSString* GetToolTip();
253
254 // Overridden to return a menu.
255 virtual NSMenu* GetMenu();
243 256
244 protected: 257 protected:
245 // For unit testing only. 258 // For unit testing only.
246 PageActionImageView() : owner_(NULL), 259 PageActionImageView() : owner_(NULL),
247 profile_(NULL), 260 profile_(NULL),
248 page_action_(NULL), 261 page_action_(NULL),
249 tracker_(NULL), 262 tracker_(NULL),
250 current_tab_id_(-1), 263 current_tab_id_(-1),
251 preview_enabled_(false) {} 264 preview_enabled_(false) {}
252 265
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // This is used for post-install visual feedback. The page_action icon 299 // This is used for post-install visual feedback. The page_action icon
287 // is briefly shown even if it hasn't been enabled by its extension. 300 // is briefly shown even if it hasn't been enabled by its extension.
288 bool preview_enabled_; 301 bool preview_enabled_;
289 302
290 // Used to register for notifications received by NotificationObserver. 303 // Used to register for notifications received by NotificationObserver.
291 NotificationRegistrar registrar_; 304 NotificationRegistrar registrar_;
292 305
293 DISALLOW_COPY_AND_ASSIGN(PageActionImageView); 306 DISALLOW_COPY_AND_ASSIGN(PageActionImageView);
294 }; 307 };
295 308
309 // ContentBlockedImageView is used to display the content settings images
310 // when types of contents are blocked on the current page.
311 class ContentBlockedImageView : public LocationBarImageView {
312 public:
313 ContentBlockedImageView(ContentSettingsType settings_type,
314 LocationBarViewMac* owner,
315 Profile* profile);
316 virtual ~ContentBlockedImageView();
317
318 // Shows a content settings bubble.
319 void OnMousePressed(NSRect bounds);
320
321 // Returns the settings type this shows up for.
322 ContentSettingsType settings_type() { return settings_type_; }
323
324 // Returns the tooltip for this Page Action image or |nil| if there is none.
325 virtual const NSString* GetToolTip();
326
327 private:
328 void SetToolTip(NSString* tooltip);
329
330 // The type of content handled by this view.
331 ContentSettingsType settings_type_;
332
333 LocationBarViewMac* owner_;
334 Profile* profile_;
335 scoped_nsobject<NSString> tooltip_;
336
337 DISALLOW_COPY_AND_ASSIGN(ContentBlockedImageView);
338 };
339 typedef ScopedVector<ContentBlockedImageView> ContentBlockedViews;
340
296 class PageActionViewList { 341 class PageActionViewList {
297 public: 342 public:
298 PageActionViewList(LocationBarViewMac* location_bar, 343 PageActionViewList(LocationBarViewMac* location_bar,
299 Profile* profile, 344 Profile* profile,
300 ToolbarModel* toolbar_model) 345 ToolbarModel* toolbar_model)
301 : owner_(location_bar), 346 : owner_(location_bar),
302 profile_(profile), 347 profile_(profile),
303 toolbar_model_(toolbar_model) {} 348 toolbar_model_(toolbar_model) {}
304 ~PageActionViewList() { 349 ~PageActionViewList() {
305 DeleteAll(); 350 DeleteAll();
(...skipping 28 matching lines...) Expand all
334 private: 379 private:
335 // Sets the SSL icon we should be showing. 380 // Sets the SSL icon we should be showing.
336 void SetSecurityIcon(ToolbarModel::Icon icon); 381 void SetSecurityIcon(ToolbarModel::Icon icon);
337 382
338 // Sets the label for the SSL icon. 383 // Sets the label for the SSL icon.
339 void SetSecurityIconLabel(); 384 void SetSecurityIconLabel();
340 385
341 // Posts |notification| to the default notification center. 386 // Posts |notification| to the default notification center.
342 void PostNotification(const NSString* notification); 387 void PostNotification(const NSString* notification);
343 388
389 // Updates visibility of the content blocked icons based on the current
390 // tab contents state.
391 void RefreshContentBlockedViews();
392
344 scoped_ptr<AutocompleteEditViewMac> edit_view_; 393 scoped_ptr<AutocompleteEditViewMac> edit_view_;
345 394
346 CommandUpdater* command_updater_; // Weak, owned by Browser. 395 CommandUpdater* command_updater_; // Weak, owned by Browser.
347 396
348 AutocompleteTextField* field_; // owned by tab controller 397 AutocompleteTextField* field_; // owned by tab controller
349 398
350 // When we get an OnAutocompleteAccept notification from the autocomplete 399 // When we get an OnAutocompleteAccept notification from the autocomplete
351 // edit, we save the input string so we can give it back to the browser on 400 // edit, we save the input string so we can give it back to the browser on
352 // the LocationBar interface via GetInputString(). 401 // the LocationBar interface via GetInputString().
353 std::wstring location_input_; 402 std::wstring location_input_;
354 403
355 // The user's desired disposition for how their input should be opened. 404 // The user's desired disposition for how their input should be opened.
356 WindowOpenDisposition disposition_; 405 WindowOpenDisposition disposition_;
357 406
358 // The view that shows the lock/warning when in HTTPS mode. 407 // The view that shows the lock/warning when in HTTPS mode.
359 SecurityImageView security_image_view_; 408 SecurityImageView security_image_view_;
360 409
361 // Any installed Page Actions. 410 // Any installed Page Actions.
362 PageActionViewList page_action_views_; 411 PageActionViewList page_action_views_;
363 412
413 // The content blocked views.
414 ContentBlockedViews content_blocked_views_;
415
364 Profile* profile_; 416 Profile* profile_;
365 417
366 Browser* browser_; 418 Browser* browser_;
367 419
368 ToolbarModel* toolbar_model_; // Weak, owned by Browser. 420 ToolbarModel* toolbar_model_; // Weak, owned by Browser.
369 421
370 // Image used in drawing keyword hint. 422 // Image used in drawing keyword hint.
371 scoped_nsobject<NSImage> tab_button_image_; 423 scoped_nsobject<NSImage> tab_button_image_;
372 424
373 // The transition type to use for the navigation. 425 // The transition type to use for the navigation.
374 PageTransition::Type transition_; 426 PageTransition::Type transition_;
375 427
376 // Used to register for notifications received by NotificationObserver. 428 // Used to register for notifications received by NotificationObserver.
377 NotificationRegistrar registrar_; 429 NotificationRegistrar registrar_;
378 430
379 DISALLOW_COPY_AND_ASSIGN(LocationBarViewMac); 431 DISALLOW_COPY_AND_ASSIGN(LocationBarViewMac);
380 }; 432 };
381 433
382 #endif // CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_ 434 #endif // CHROME_BROWSER_COCOA_LOCATION_BAR_VIEW_MAC_H_
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/extension_installed_bubble_controller.mm ('k') | chrome/browser/cocoa/location_bar_view_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698