Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Added support in Metro mode for retrieving the information about the …
Browse files Browse the repository at this point in the history
…currently displayed tab url and title.

This is retrieved via a registered window message sent by the metro driver.
The information is used by the share charm in metro.

BUG=125673
R=cpu,sky
Review URL: https://chromiumcodereview.appspot.com/10287005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134995 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ananta@chromium.org committed May 2, 2012
1 parent 9ff974d commit 4c0f3bd
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
9 changes: 9 additions & 0 deletions base/win/metro.cc
Expand Up @@ -4,13 +4,22 @@

#include "base/win/metro.h"

#include "base/string_util.h"

namespace base {
namespace win {

HMODULE GetMetroModule() {
return GetModuleHandleA("metro_driver.dll");
}

wchar_t* LocalAllocAndCopyString(const string16& src) {
size_t dest_size = (src.length() + 1) * sizeof(wchar_t);
wchar_t* dest = reinterpret_cast<wchar_t*>(LocalAlloc(LPTR, dest_size));
base::wcslcpy(dest, src.c_str(), dest_size);
return dest;
}

} // namespace win
} // namespace base

5 changes: 5 additions & 0 deletions base/win/metro.h
Expand Up @@ -9,6 +9,7 @@
#include <windows.h>

#include "base/base_export.h"
#include "base/string16.h"

namespace base {
namespace win {
Expand Down Expand Up @@ -44,6 +45,10 @@ struct CurrentTabInfo {
// indicates that the metro dll was not loaded in the process.
BASE_EXPORT HMODULE GetMetroModule();

// Allocates and returns the destination string via the LocalAlloc API after
// copying the src to it.
BASE_EXPORT wchar_t* LocalAllocAndCopyString(const string16& src);

} // namespace win
} // namespace base

Expand Down
46 changes: 43 additions & 3 deletions chrome/browser/ui/views/frame/browser_frame_win.cc
Expand Up @@ -10,6 +10,7 @@
#include <set>

#include "base/command_line.h"
#include "base/utf_string_conversions.h"
#include "base/win/metro.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/search_engines/template_url.h"
Expand All @@ -24,7 +25,9 @@
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/browser_accessibility_state.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/page_transition_types.h"
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/models/simple_menu_model.h"
Expand All @@ -50,6 +53,7 @@ static int explicit_show_state = -1;

using content::OpenURLParams;
using content::Referrer;
using content::WebContents;

///////////////////////////////////////////////////////////////////////////////
// BrowserFrameWin, public:
Expand Down Expand Up @@ -208,9 +212,15 @@ LRESULT BrowserFrameWin::OnWndProc(UINT message,
LPARAM l_param) {
static const UINT metro_navigation_search_message =
RegisterWindowMessage(chrome::kMetroNavigationAndSearchMessage);
if (message == metro_navigation_search_message)
HandleMetroRequest(w_param, l_param);

static const UINT metro_get_current_tab_info_message =
RegisterWindowMessage(chrome::kMetroGetCurrentTabInfoMessage);

if (message == metro_navigation_search_message) {
HandleMetroNavSearchRequest(w_param, l_param);
} else if (message == metro_get_current_tab_info_message) {
GetMetroCurrentTabInfo(w_param);
}
return views::NativeWidgetWin::OnWndProc(message, w_param, l_param);
}

Expand Down Expand Up @@ -307,7 +317,8 @@ void BrowserFrameWin::AddFrameToggleItems() {
}
}

void BrowserFrameWin::HandleMetroRequest(WPARAM w_param, LPARAM l_param) {
void BrowserFrameWin::HandleMetroNavSearchRequest(WPARAM w_param,
LPARAM l_param) {
if (!base::win::GetMetroModule()) {
NOTREACHED() << "Received unexpected metro navigation request";
return;
Expand Down Expand Up @@ -346,6 +357,35 @@ void BrowserFrameWin::HandleMetroRequest(WPARAM w_param, LPARAM l_param) {
}
}

void BrowserFrameWin::GetMetroCurrentTabInfo(WPARAM w_param) {
if (!base::win::GetMetroModule()) {
NOTREACHED() << "Received unexpected metro request";
return;
}

if (!w_param) {
NOTREACHED() << "Invalid metro request parameter";
return;
}

base::win::CurrentTabInfo* current_tab_info =
reinterpret_cast<base::win::CurrentTabInfo*>(w_param);

Browser* browser = browser_view()->browser();
DCHECK(browser);

// We allocate memory for the title and url via LocalAlloc. The caller has to
// free the memory via LocalFree.
current_tab_info->title = base::win::LocalAllocAndCopyString(
browser->GetWindowTitleForCurrentTab());

WebContents* current_tab = browser->GetSelectedWebContents();
DCHECK(current_tab);

current_tab_info->url = base::win::LocalAllocAndCopyString(
UTF8ToWide(current_tab->GetURL().spec()));
}


////////////////////////////////////////////////////////////////////////////////
// BrowserFrame, public:
Expand Down
7 changes: 5 additions & 2 deletions chrome/browser/ui/views/frame/browser_frame_win.h
Expand Up @@ -77,8 +77,11 @@ class BrowserFrameWin : public views::NativeWidgetWin,
// Adds optional debug items for frame type toggling.
void AddFrameToggleItems();

// Handles metro navigation search requests.
void HandleMetroRequest(WPARAM w_param, LPARAM l_param);
// Handles metro navigation and search requests.
void HandleMetroNavSearchRequest(WPARAM w_param, LPARAM l_param);

// Returns information about the currently displayed tab in metro mode.
void GetMetroCurrentTabInfo(WPARAM w_param);

// The BrowserView is our ClientView. This is a pointer to it.
BrowserView* browser_view_;
Expand Down
3 changes: 2 additions & 1 deletion chrome/common/chrome_constants.cc
Expand Up @@ -203,7 +203,8 @@ const char kPreReadEnvironmentVariable[] = "CHROME_PRE_READ_EXPERIMENT";
const wchar_t kMetroChromeUserDataSubDir[] = L"Metro";
const wchar_t kMetroNavigationAndSearchMessage[] =
L"CHROME_METRO_NAV_SEARCH_REQUEST";

const wchar_t kMetroGetCurrentTabInfoMessage[] =
L"CHROME_METRO_GET_CURRENT_TAB_INFO";
#endif

} // namespace chrome
Expand Down
2 changes: 2 additions & 0 deletions chrome/common/chrome_constants.h
Expand Up @@ -134,6 +134,8 @@ extern const char kPreReadEnvironmentVariable[];
extern const wchar_t kMetroChromeUserDataSubDir[];
// Used by Metro Chrome to initiate navigation and search requests.
extern const wchar_t kMetroNavigationAndSearchMessage[];
// Used by Metro Chrome to get information about the current tab.
extern const wchar_t kMetroGetCurrentTabInfoMessage[];
#endif

} // namespace chrome
Expand Down

0 comments on commit 4c0f3bd

Please sign in to comment.