diff options
author | snej@chromium.org <snej@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-03 23:06:51 +0000 |
---|---|---|
committer | snej@chromium.org <snej@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-03 23:06:51 +0000 |
commit | 89d6e6e3456280a12b4b806de8cbe3d049476df6 (patch) | |
tree | fe449cc80e3d1780c2db174d61836de639db0501 /chrome | |
parent | 758338d7593c0b403ffde83b5490c9a19e47ddaa (diff) | |
download | chromium_src-89d6e6e3456280a12b4b806de8cbe3d049476df6.zip chromium_src-89d6e6e3456280a12b4b806de8cbe3d049476df6.tar.gz chromium_src-89d6e6e3456280a12b4b806de8cbe3d049476df6.tar.bz2 |
Implement "Email Link To Page" menu command.
This menu item only exists in the Mac build, but the code is cross-platform so it could be hooked up on other platforms as well, if desired.
It works by generating a URL of the form
mailto:?subject=Fwd:%20PAGETITLE&body=%0A%0APAGEURL
and telling platform_utils to open it.
This is my first patch involving command handling; I've tried to follow the way similar menu commands
like Print are implemented, but feel free to tell me if there are better ways.
I didn't find any place for unit tests for TabContents; if this needs tests, let me know where they should go.
BUG=29232
TEST=none
Review URL: http://codereview.chromium.org/466019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33746 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/chrome_dll_resource.h | 1 | ||||
-rw-r--r-- | chrome/app/nibs/MainMenu.xib | 22 | ||||
-rw-r--r-- | chrome/browser/browser.cc | 9 | ||||
-rw-r--r-- | chrome/browser/browser.h | 1 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 9 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 4 | ||||
-rw-r--r-- | chrome/common/platform_util_mac.mm | 11 |
7 files changed, 47 insertions, 10 deletions
diff --git a/chrome/app/chrome_dll_resource.h b/chrome/app/chrome_dll_resource.h index 4aee050..180f136 100644 --- a/chrome/app/chrome_dll_resource.h +++ b/chrome/app/chrome_dll_resource.h @@ -117,6 +117,7 @@ #define IDC_PRINT 35004 #define IDC_SAVE_PAGE 35005 #define IDC_ENCODING_MENU 35006 +#define IDC_EMAIL_PAGE_LOCATION 35007 // When adding a new encoding to this list, be sure to append it to the // EncodingMenuController::kValidEncodingIds array in diff --git a/chrome/app/nibs/MainMenu.xib b/chrome/app/nibs/MainMenu.xib index ca2bea1..bb33b2a 100644 --- a/chrome/app/nibs/MainMenu.xib +++ b/chrome/app/nibs/MainMenu.xib @@ -2,13 +2,13 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">9L30</string> - <string key="IBDocument.InterfaceBuilderVersion">680</string> + <string key="IBDocument.SystemVersion">9L31a</string> + <string key="IBDocument.InterfaceBuilderVersion">677</string> <string key="IBDocument.AppKitVersion">949.54</string> <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> - <integer value="57"/> + <integer value="451"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -362,10 +362,12 @@ <object class="NSMenuItem" id="120844338"> <reference key="NSMenu" ref="720053764"/> <string key="NSTitle">^IDS_EMAIL_PAGE_LOCATION_MAC</string> - <string key="NSKeyEquiv"/> + <string key="NSKeyEquiv">I</string> + <int key="NSKeyEquivModMask">1048576</int> <int key="NSMnemonicLoc">2147483647</int> <reference key="NSOnImage" ref="353210768"/> <reference key="NSMixedImage" ref="549394948"/> + <int key="NSTag">35007</int> </object> <object class="NSMenuItem" id="1010469920"> <reference key="NSMenu" ref="720053764"/> @@ -1669,6 +1671,14 @@ </object> <int key="connectionID">667</int> </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">commandDispatch:</string> + <reference key="source" ref="1014"/> + <reference key="destination" ref="120844338"/> + </object> + <int key="connectionID">668</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -2920,7 +2930,7 @@ <reference ref="9"/> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> - <string>{{305, 468}, {353, 303}}</string> + <string>{{648, 422}, {353, 303}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <reference ref="9"/> <string>{{323, 672}, {199, 203}}</string> @@ -2952,7 +2962,7 @@ </object> </object> <nil key="sourceID"/> - <int key="maxID">667</int> + <int key="maxID">668</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index b9e6cb5..32cb834 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1039,6 +1039,11 @@ void Browser::ClosePopups() { } #endif +void Browser::EmailPageLocation() { + UserMetrics::RecordAction("EmailPageLocation", profile_); + GetSelectedTabContents()->EmailPageLocation(); +} + void Browser::Print() { UserMetrics::RecordAction("PrintPreview", profile_); GetSelectedTabContents()->PrintPreview(); @@ -1464,6 +1469,7 @@ void Browser::ExecuteCommandWithDisposition( #if defined(OS_WIN) case IDC_CLOSE_POPUPS: ClosePopups(); break; #endif + case IDC_EMAIL_PAGE_LOCATION: EmailPageLocation(); break; case IDC_PRINT: Print(); break; case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break; case IDC_ENCODING_UTF8: @@ -2385,6 +2391,7 @@ void Browser::InitCommandState() { // Page-related commands command_updater_.UpdateCommandEnabled(IDC_CLOSE_POPUPS, true); + command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true); command_updater_.UpdateCommandEnabled(IDC_PRINT, true); command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true); command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true); @@ -2549,6 +2556,8 @@ void Browser::UpdateCommandsForTabState() { // Show various bits of UI command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, web_app::IsValidUrl(current_tab->GetURL())); + command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, + current_tab->ShouldDisplayURL() && current_tab->GetURL().is_valid()); } void Browser::UpdateStopGoState(bool is_loading, bool force) { diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index cf92360..6507c98 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -373,6 +373,7 @@ class Browser : public TabStripModelDelegate, void ClosePopups(); #endif void Print(); + void EmailPageLocation(); void ToggleEncodingAutoDetect(); void OverrideEncoding(int encoding_id); diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 4799e6e..300be68d 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -58,6 +58,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension_action.h" #include "chrome/common/notification_service.h" +#include "chrome/common/platform_util.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "chrome/common/render_messages.h" @@ -1100,6 +1101,14 @@ bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, return save_package_->Init(); } +void TabContents::EmailPageLocation() { + std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false); + std::string page_url = EscapeQueryParamValue(GetURL().spec(), false); + std::string mailto = std::string("mailto:?subject=Fwd:%20") + + title + "&body=%0A%0A" + page_url; + platform_util::OpenExternal(GURL(mailto)); +} + void TabContents::PrintPreview() { // We don't show the print preview yet, only the print dialog. PrintNow(); diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 50aae3f..072e430 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -551,6 +551,10 @@ class TabContents : public PageNavigator, bool SavePage(const FilePath& main_file, const FilePath& dir_path, SavePackage::SavePackageType save_type); + // Tells the user's email client to open a compose window containing the + // current page's URL. + void EmailPageLocation(); + // Displays asynchronously a print preview (generated by the renderer) if not // already displayed and ask the user for its preferred print settings with // the "Print..." dialog box. (managed by the print worker thread). diff --git a/chrome/common/platform_util_mac.mm b/chrome/common/platform_util_mac.mm index cf858eb..2c9883a 100644 --- a/chrome/common/platform_util_mac.mm +++ b/chrome/common/platform_util_mac.mm @@ -20,21 +20,24 @@ namespace platform_util { void ShowItemInFolder(const FilePath& full_path) { DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); NSString* path_string = base::SysUTF8ToNSString(full_path.value()); - [[NSWorkspace sharedWorkspace] selectFile:path_string - inFileViewerRootedAtPath:nil]; + if (!path_string || ![[NSWorkspace sharedWorkspace] selectFile:path_string + inFileViewerRootedAtPath:nil]) + LOG(WARNING) << "NSWorkspace failed to select file " << full_path.value(); } void OpenItem(const FilePath& full_path) { DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); NSString* path_string = base::SysUTF8ToNSString(full_path.value()); - [[NSWorkspace sharedWorkspace] openFile:path_string]; + if (!path_string || ![[NSWorkspace sharedWorkspace] openFile:path_string]) + LOG(WARNING) << "NSWorkspace failed to open file " << full_path.value(); } void OpenExternal(const GURL& url) { DCHECK_EQ([NSThread currentThread], [NSThread mainThread]); NSString* url_string = base::SysUTF8ToNSString(url.spec()); NSURL* ns_url = [NSURL URLWithString:url_string]; - [[NSWorkspace sharedWorkspace] openURL:ns_url]; + if (!ns_url || ![[NSWorkspace sharedWorkspace] openURL:ns_url]) + LOG(WARNING) << "NSWorkspace failed to open URL " << url; } gfx::NativeWindow GetTopLevel(gfx::NativeView view) { |