PageRenderTime 36ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llfloaterhelpbrowser.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 162 lines | 101 code | 26 blank | 35 comment | 7 complexity | 9436a16c8a22bee21d437eac02cb6899 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloaterhelpbrowser.cpp
  3. * @brief HTML Help floater - uses embedded web browser control
  4. *
  5. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llfloaterhelpbrowser.h"
  28. #include "llfloaterreg.h"
  29. #include "llpluginclassmedia.h"
  30. #include "llmediactrl.h"
  31. #include "llviewerwindow.h"
  32. #include "llviewercontrol.h"
  33. #include "llweb.h"
  34. #include "llui.h"
  35. #include "llurlhistory.h"
  36. #include "llmediactrl.h"
  37. #include "llviewermedia.h"
  38. #include "llviewerhelp.h"
  39. LLFloaterHelpBrowser::LLFloaterHelpBrowser(const LLSD& key)
  40. : LLFloater(key)
  41. {
  42. }
  43. BOOL LLFloaterHelpBrowser::postBuild()
  44. {
  45. mBrowser = getChild<LLMediaCtrl>("browser");
  46. mBrowser->addObserver(this);
  47. mBrowser->setErrorPageURL(gSavedSettings.getString("GenericErrorPageURL"));
  48. childSetAction("open_browser", onClickOpenWebBrowser, this);
  49. buildURLHistory();
  50. return TRUE;
  51. }
  52. void LLFloaterHelpBrowser::buildURLHistory()
  53. {
  54. // Get all of the entries in the "browser" collection
  55. LLSD browser_history = LLURLHistory::getURLHistory("browser");
  56. // initialize URL history in the plugin
  57. LLPluginClassMedia *plugin = mBrowser->getMediaPlugin();
  58. if (plugin)
  59. {
  60. plugin->initializeUrlHistory(browser_history);
  61. }
  62. }
  63. void LLFloaterHelpBrowser::onOpen(const LLSD& key)
  64. {
  65. gSavedSettings.setBOOL("HelpFloaterOpen", TRUE);
  66. std::string topic = key.asString();
  67. if (topic == "__local")
  68. {
  69. mBrowser->navigateToLocalPage( "help-offline" , "index.html" );
  70. }
  71. else
  72. {
  73. mBrowser->navigateTo(LLViewerHelp::instance().getURL(topic));
  74. }
  75. }
  76. //virtual
  77. void LLFloaterHelpBrowser::onClose(bool app_quitting)
  78. {
  79. if (!app_quitting)
  80. {
  81. gSavedSettings.setBOOL("HelpFloaterOpen", FALSE);
  82. }
  83. // really really destroy the help browser when it's closed, it'll be recreated.
  84. destroy(); // really destroy this dialog on closure, it's relatively heavyweight.
  85. }
  86. void LLFloaterHelpBrowser::handleMediaEvent(LLPluginClassMedia* self, EMediaEvent event)
  87. {
  88. switch (event)
  89. {
  90. case MEDIA_EVENT_LOCATION_CHANGED:
  91. setCurrentURL(self->getLocation());
  92. break;
  93. case MEDIA_EVENT_NAVIGATE_BEGIN:
  94. getChild<LLUICtrl>("status_text")->setValue(getString("loading_text"));
  95. break;
  96. case MEDIA_EVENT_NAVIGATE_COMPLETE:
  97. getChild<LLUICtrl>("status_text")->setValue(getString("done_text"));
  98. break;
  99. default:
  100. break;
  101. }
  102. }
  103. void LLFloaterHelpBrowser::setCurrentURL(const std::string& url)
  104. {
  105. mCurrentURL = url;
  106. // redirects will navigate momentarily to about:blank, don't add to history
  107. if (mCurrentURL != "about:blank")
  108. {
  109. // Serialize url history
  110. LLURLHistory::removeURL("browser", mCurrentURL);
  111. LLURLHistory::addURL("browser", mCurrentURL);
  112. }
  113. }
  114. //static
  115. void LLFloaterHelpBrowser::onClickClose(void* user_data)
  116. {
  117. LLFloaterHelpBrowser* self = (LLFloaterHelpBrowser*)user_data;
  118. self->closeFloater();
  119. }
  120. //static
  121. void LLFloaterHelpBrowser::onClickOpenWebBrowser(void* user_data)
  122. {
  123. LLFloaterHelpBrowser* self = (LLFloaterHelpBrowser*)user_data;
  124. std::string url = self->mCurrentURL.empty() ?
  125. self->mBrowser->getHomePageUrl() :
  126. self->mCurrentURL;
  127. LLWeb::loadURLExternal(url);
  128. }
  129. void LLFloaterHelpBrowser::openMedia(const std::string& media_url)
  130. {
  131. // explicitly make the media mime type for this floater since it will
  132. // only ever display one type of content (Web).
  133. mBrowser->setHomePageUrl(media_url, "text/html");
  134. mBrowser->navigateTo(media_url, "text/html");
  135. setCurrentURL(media_url);
  136. }