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

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.cc

Issue 339153002: Use suggested filename for "Save Link As" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback Created 6 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/renderer_context_menu/render_view_context_menu_browsert est_util.h" 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" 11 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
11 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
13 #include "content/public/test/test_utils.h"
12 14
13 ContextMenuNotificationObserver::ContextMenuNotificationObserver( 15 ContextMenuNotificationObserver::ContextMenuNotificationObserver(
14 int command_to_execute) 16 int command_to_execute)
15 : command_to_execute_(command_to_execute) { 17 : command_to_execute_(command_to_execute) {
16 registrar_.Add(this, 18 registrar_.Add(this,
17 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, 19 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
18 content::NotificationService::AllSources()); 20 content::NotificationService::AllSources());
19 } 21 }
20 22
21 ContextMenuNotificationObserver::~ContextMenuNotificationObserver() { 23 ContextMenuNotificationObserver::~ContextMenuNotificationObserver() {
22 } 24 }
23 25
24 void ContextMenuNotificationObserver::Observe( 26 void ContextMenuNotificationObserver::Observe(
25 int type, 27 int type,
26 const content::NotificationSource& source, 28 const content::NotificationSource& source,
27 const content::NotificationDetails& details) { 29 const content::NotificationDetails& details) {
28 switch (type) { 30 switch (type) {
29 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: { 31 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: {
30 RenderViewContextMenu* context_menu = 32 RenderViewContextMenu* context_menu =
31 content::Source<RenderViewContextMenu>(source).ptr(); 33 content::Source<RenderViewContextMenu>(source).ptr();
32 base::MessageLoop::current()->PostTask( 34 base::MessageLoop::current()->PostTask(
33 FROM_HERE, 35 FROM_HERE,
34 base::Bind(&ContextMenuNotificationObserver::ExecuteCommand, 36 base::Bind(&ContextMenuNotificationObserver::ExecuteCommand,
35 base::Unretained(this), context_menu)); 37 base::Unretained(this),
38 context_menu));
36 break; 39 break;
37 } 40 }
38 41
39 default: 42 default:
40 NOTREACHED(); 43 NOTREACHED();
41 } 44 }
42 } 45 }
43 46
44 void ContextMenuNotificationObserver::ExecuteCommand( 47 void ContextMenuNotificationObserver::ExecuteCommand(
45 RenderViewContextMenu* context_menu) { 48 RenderViewContextMenu* context_menu) {
46 context_menu->ExecuteCommand(command_to_execute_, 0); 49 context_menu->ExecuteCommand(command_to_execute_, 0);
47 context_menu->Cancel(); 50 context_menu->Cancel();
48 } 51 }
52
53 SaveLinkAsContextMenuObserver::SaveLinkAsContextMenuObserver(
54 const content::NotificationSource& source)
55 : ContextMenuNotificationObserver(IDC_CONTENT_CONTEXT_SAVELINKAS),
56 menu_visible_(false) {
57 }
58
59 SaveLinkAsContextMenuObserver::~SaveLinkAsContextMenuObserver() {
60 }
61
62 void SaveLinkAsContextMenuObserver::Observe(
63 int type,
64 const content::NotificationSource& source,
65 const content::NotificationDetails& details) {
66 switch (type) {
67 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: {
68 menu_visible_ = true;
69 RenderViewContextMenu* context_menu =
70 content::Source<RenderViewContextMenu>(source).ptr();
71 base::MessageLoop::current()->PostTask(
72 FROM_HERE,
73 base::Bind(&SaveLinkAsContextMenuObserver::Cancel,
74 base::Unretained(this),
75 context_menu));
76 break;
77 }
78
79 default:
80 NOTREACHED();
81 }
82 }
83
84 void SaveLinkAsContextMenuObserver::WaitForMenu() {
85 content::WindowedNotificationObserver menu_observer(
86 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
87 content::NotificationService::AllSources());
88 if (!menu_visible_)
89 menu_observer.Wait();
90 menu_visible_ = false;
91 }
92
93 base::string16 SaveLinkAsContextMenuObserver::GetSuggestedFilename() {
94 return params_.suggested_filename;
95 }
96
97 void SaveLinkAsContextMenuObserver::Cancel(
98 RenderViewContextMenu* context_menu) {
99 params_ = context_menu->params();
100 context_menu->Cancel();
101 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h ('k') | content/common/frame_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698